src/HOL/Decision_Procs/Cooper.thy
changeset 55844 fc04c24ad9ee
parent 55814 aefa1db74d9d
child 55885 c871a2e751ec
equal deleted inserted replaced
55843:3fa61f39d1f2 55844:fc04c24ad9ee
    23 | "num_size (Add a b) = 1 + num_size a + num_size b"
    23 | "num_size (Add a b) = 1 + num_size a + num_size b"
    24 | "num_size (Sub a b) = 3 + num_size a + num_size b"
    24 | "num_size (Sub a b) = 3 + num_size a + num_size b"
    25 | "num_size (CN n c a) = 4 + num_size a"
    25 | "num_size (CN n c a) = 4 + num_size a"
    26 | "num_size (Mul c a) = 1 + num_size a"
    26 | "num_size (Mul c a) = 1 + num_size a"
    27 
    27 
    28 primrec Inum :: "int list \<Rightarrow> num \<Rightarrow> int" where
    28 primrec Inum :: "int list \<Rightarrow> num \<Rightarrow> int"
       
    29 where
    29   "Inum bs (C c) = c"
    30   "Inum bs (C c) = c"
    30 | "Inum bs (Bound n) = bs!n"
    31 | "Inum bs (Bound n) = bs!n"
    31 | "Inum bs (CN n c a) = c * (bs!n) + (Inum bs a)"
    32 | "Inum bs (CN n c a) = c * (bs!n) + (Inum bs a)"
    32 | "Inum bs (Neg a) = -(Inum bs a)"
    33 | "Inum bs (Neg a) = -(Inum bs a)"
    33 | "Inum bs (Add a b) = Inum bs a + Inum bs b"
    34 | "Inum bs (Add a b) = Inum bs a + Inum bs b"
   265 | "isatom (Closed P) = True"
   266 | "isatom (Closed P) = True"
   266 | "isatom (NClosed P) = True"
   267 | "isatom (NClosed P) = True"
   267 | "isatom p = False"
   268 | "isatom p = False"
   268 
   269 
   269 lemma numsubst0_numbound0:
   270 lemma numsubst0_numbound0:
   270   assumes nb: "numbound0 t"
   271   assumes "numbound0 t"
   271   shows "numbound0 (numsubst0 t a)"
   272   shows "numbound0 (numsubst0 t a)"
   272   using nb apply (induct a)
   273   using assms
       
   274   apply (induct a)
   273   apply simp_all
   275   apply simp_all
   274   apply (case_tac nat, simp_all)
   276   apply (case_tac nat)
       
   277   apply simp_all
   275   done
   278   done
   276 
   279 
   277 lemma subst0_bound0:
   280 lemma subst0_bound0:
   278   assumes qf: "qfree p" and nb: "numbound0 t"
   281   assumes qf: "qfree p"
       
   282     and nb: "numbound0 t"
   279   shows "bound0 (subst0 t p)"
   283   shows "bound0 (subst0 t p)"
   280   using qf numsubst0_numbound0[OF nb] by (induct p) auto
   284   using qf numsubst0_numbound0[OF nb] by (induct p) auto
   281 
   285 
   282 lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
   286 lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
   283   by (induct p) simp_all
   287   by (induct p) simp_all
   354 
   358 
   355 lemma DJ_qf:
   359 lemma DJ_qf:
   356   assumes fqf: "\<forall>p. qfree p \<longrightarrow> qfree (f p)"
   360   assumes fqf: "\<forall>p. qfree p \<longrightarrow> qfree (f p)"
   357   shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
   361   shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
   358 proof clarify
   362 proof clarify
   359   fix p assume qf: "qfree p"
   363   fix p
   360   have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
   364   assume qf: "qfree p"
       
   365   have th: "DJ f p = evaldjf f (disjuncts p)"
       
   366     by (simp add: DJ_def)
   361   from disjuncts_qf[OF qf] have "\<forall>q\<in> set (disjuncts p). qfree q" .
   367   from disjuncts_qf[OF qf] have "\<forall>q\<in> set (disjuncts p). qfree q" .
   362   with fqf have th':"\<forall>q\<in> set (disjuncts p). qfree (f q)" by blast
   368   with fqf have th':"\<forall>q\<in> set (disjuncts p). qfree (f q)"
   363 
   369     by blast
   364   from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
   370   from evaldjf_qf[OF th'] th show "qfree (DJ f p)"
       
   371     by simp
   365 qed
   372 qed
   366 
   373 
   367 lemma DJ_qe:
   374 lemma DJ_qe:
   368   assumes qe: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bbs bs (qe p) = Ifm bbs bs (E p))"
   375   assumes qe: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bbs bs (qe p) = Ifm bbs bs (E p))"
   369   shows "\<forall>bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bbs bs ((DJ qe p)) = Ifm bbs bs (E p))"
   376   shows "\<forall>bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bbs bs ((DJ qe p)) = Ifm bbs bs (E p))"
   370 proof clarify
   377 proof clarify
   371   fix p :: fm and bs
   378   fix p :: fm
       
   379   fix bs
   372   assume qf: "qfree p"
   380   assume qf: "qfree p"
   373   from qe have qth: "\<forall>p. qfree p \<longrightarrow> qfree (qe p)" by blast
   381   from qe have qth: "\<forall>p. qfree p \<longrightarrow> qfree (qe p)"
   374   from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
   382     by blast
       
   383   from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)"
       
   384     by auto
   375   have "Ifm bbs bs (DJ qe p) = (\<exists>q\<in> set (disjuncts p). Ifm bbs bs (qe q))"
   385   have "Ifm bbs bs (DJ qe p) = (\<exists>q\<in> set (disjuncts p). Ifm bbs bs (qe q))"
   376     by (simp add: DJ_def evaldjf_ex)
   386     by (simp add: DJ_def evaldjf_ex)
   377   also have "\<dots> = (\<exists>q \<in> set(disjuncts p). Ifm bbs bs (E q))"
   387   also have "\<dots> = (\<exists>q \<in> set(disjuncts p). Ifm bbs bs (E q))"
   378     using qe disjuncts_qf[OF qf] by auto
   388     using qe disjuncts_qf[OF qf] by auto
   379   also have "\<dots> = Ifm bbs bs (E p)"
   389   also have "\<dots> = Ifm bbs bs (E p)"
   397 | "bnds (Mul i a) = bnds a"
   407 | "bnds (Mul i a) = bnds a"
   398 | "bnds a = []"
   408 | "bnds a = []"
   399 
   409 
   400 fun lex_ns:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
   410 fun lex_ns:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
   401 where
   411 where
   402   "lex_ns [] ms = True"
   412   "lex_ns [] ms \<longleftrightarrow> True"
   403 | "lex_ns ns [] = False"
   413 | "lex_ns ns [] \<longleftrightarrow> False"
   404 | "lex_ns (n#ns) (m#ms) = (n<m \<or> ((n = m) \<and> lex_ns ns ms)) "
   414 | "lex_ns (n # ns) (m # ms) \<longleftrightarrow> n < m \<or> (n = m \<and> lex_ns ns ms)"
   405 
   415 
   406 definition lex_bnd :: "num \<Rightarrow> num \<Rightarrow> bool"
   416 definition lex_bnd :: "num \<Rightarrow> num \<Rightarrow> bool"
   407   where "lex_bnd t s = lex_ns (bnds t) (bnds s)"
   417   where "lex_bnd t s = lex_ns (bnds t) (bnds s)"
   408 
   418 
   409 consts numadd:: "num \<times> num \<Rightarrow> num"
   419 consts numadd:: "num \<times> num \<Rightarrow> num"
   438   | "numadd a b = Add a b"
   448   | "numadd a b = Add a b"
   439 apply pat_completeness apply auto*)
   449 apply pat_completeness apply auto*)
   440 
   450 
   441 lemma numadd: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
   451 lemma numadd: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
   442   apply (induct t s rule: numadd.induct, simp_all add: Let_def)
   452   apply (induct t s rule: numadd.induct, simp_all add: Let_def)
   443   apply (case_tac "c1 + c2 = 0", case_tac "n1 \<le> n2", simp_all)
   453   apply (case_tac "c1 + c2 = 0")
       
   454   apply (case_tac "n1 \<le> n2")
       
   455   apply simp_all
   444    apply (case_tac "n1 = n2")
   456    apply (case_tac "n1 = n2")
   445     apply(simp_all add: algebra_simps)
   457     apply (simp_all add: algebra_simps)
   446   apply(simp add: distrib_right[symmetric])
   458   apply (simp add: distrib_right[symmetric])
   447   done
   459   done
   448 
   460 
   449 lemma numadd_nb: "numbound0 t \<Longrightarrow> numbound0 s \<Longrightarrow> numbound0 (numadd (t, s))"
   461 lemma numadd_nb: "numbound0 t \<Longrightarrow> numbound0 s \<Longrightarrow> numbound0 (numadd (t, s))"
   450   by (induct t s rule: numadd.induct) (auto simp add: Let_def)
   462   by (induct t s rule: numadd.induct) (auto simp add: Let_def)
   451 
   463 
   452 fun nummul :: "int \<Rightarrow> num \<Rightarrow> num"
   464 fun nummul :: "int \<Rightarrow> num \<Rightarrow> num"
   453 where
   465 where
   454   "nummul i (C j) = C (i * j)"
   466   "nummul i (C j) = C (i * j)"
   455 | "nummul i (CN n c t) = CN n (c*i) (nummul i t)"
   467 | "nummul i (CN n c t) = CN n (c * i) (nummul i t)"
   456 | "nummul i t = Mul i t"
   468 | "nummul i t = Mul i t"
   457 
   469 
   458 lemma nummul: "Inum bs (nummul i t) = Inum bs (Mul i t)"
   470 lemma nummul: "Inum bs (nummul i t) = Inum bs (Mul i t)"
   459   by (induct t arbitrary: i rule: nummul.induct) (auto simp add: algebra_simps numadd)
   471   by (induct t arbitrary: i rule: nummul.induct) (auto simp add: algebra_simps numadd)
   460 
   472 
   511 lemma not_bn: "bound0 p \<Longrightarrow> bound0 (not p)"
   523 lemma not_bn: "bound0 p \<Longrightarrow> bound0 (not p)"
   512   by (cases p) auto
   524   by (cases p) auto
   513 
   525 
   514 definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   526 definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   515   where
   527   where
   516     "conj p q = (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else And p q)"
   528     "conj p q =
       
   529       (if p = F \<or> q = F then F
       
   530        else if p = T then q
       
   531        else if q = T then p
       
   532        else And p q)"
   517 
   533 
   518 lemma conj: "Ifm bbs bs (conj p q) = Ifm bbs bs (And p q)"
   534 lemma conj: "Ifm bbs bs (conj p q) = Ifm bbs bs (And p q)"
   519   by (cases "p=F \<or> q=F", simp_all add: conj_def) (cases p, simp_all)
   535   by (cases "p = F \<or> q = F", simp_all add: conj_def) (cases p, simp_all)
   520 
   536 
   521 lemma conj_qf: "qfree p \<Longrightarrow> qfree q \<Longrightarrow> qfree (conj p q)"
   537 lemma conj_qf: "qfree p \<Longrightarrow> qfree q \<Longrightarrow> qfree (conj p q)"
   522   using conj_def by auto
   538   using conj_def by auto
   523 
   539 
   524 lemma conj_nb: "bound0 p \<Longrightarrow> bound0 q \<Longrightarrow> bound0 (conj p q)"
   540 lemma conj_nb: "bound0 p \<Longrightarrow> bound0 q \<Longrightarrow> bound0 (conj p q)"
   525   using conj_def by auto
   541   using conj_def by auto
   526 
   542 
   527 definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   543 definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   528   where
   544   where
   529     "disj p q =
   545     "disj p q =
   530       (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p else Or p q)"
   546       (if p = T \<or> q = T then T
       
   547        else if p = F then q
       
   548        else if q = F then p
       
   549        else Or p q)"
   531 
   550 
   532 lemma disj: "Ifm bbs bs (disj p q) = Ifm bbs bs (Or p q)"
   551 lemma disj: "Ifm bbs bs (disj p q) = Ifm bbs bs (Or p q)"
   533   by (cases "p=T \<or> q=T", simp_all add: disj_def) (cases p, simp_all)
   552   by (cases "p=T \<or> q=T", simp_all add: disj_def) (cases p, simp_all)
   534 
   553 
   535 lemma disj_qf: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
   554 lemma disj_qf: "qfree p \<Longrightarrow> qfree q \<Longrightarrow> qfree (disj p q)"
   536   using disj_def by auto
   555   using disj_def by auto
   537 
   556 
   538 lemma disj_nb: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
   557 lemma disj_nb: "bound0 p \<Longrightarrow> bound0 q \<Longrightarrow> bound0 (disj p q)"
   539   using disj_def by auto
   558   using disj_def by auto
   540 
   559 
   541 definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   560 definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   542   where
   561   where
   543     "imp p q = (if (p = F \<or> q=T) then T else if p=T then q else if q=F then not p else Imp p q)"
   562     "imp p q =
       
   563       (if p = F \<or> q = T then T
       
   564        else if p = T then q
       
   565        else if q = F then not p
       
   566        else Imp p q)"
   544 
   567 
   545 lemma imp: "Ifm bbs bs (imp p q) = Ifm bbs bs (Imp p q)"
   568 lemma imp: "Ifm bbs bs (imp p q) = Ifm bbs bs (Imp p q)"
   546   by (cases "p=F \<or> q=T", simp_all add: imp_def, cases p) (simp_all add: not)
   569   by (cases "p = F \<or> q = T", simp_all add: imp_def, cases p) (simp_all add: not)
   547 
   570 
   548 lemma imp_qf: "qfree p \<Longrightarrow> qfree q \<Longrightarrow> qfree (imp p q)"
   571 lemma imp_qf: "qfree p \<Longrightarrow> qfree q \<Longrightarrow> qfree (imp p q)"
   549   using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def,cases p) (simp_all add: not_qf)
   572   using imp_def by (cases "p = F \<or> q = T", simp_all add: imp_def, cases p) (simp_all add: not_qf)
   550 
   573 
   551 lemma imp_nb: "bound0 p \<Longrightarrow> bound0 q \<Longrightarrow> bound0 (imp p q)"
   574 lemma imp_nb: "bound0 p \<Longrightarrow> bound0 q \<Longrightarrow> bound0 (imp p q)"
   552   using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def,cases p) simp_all
   575   using imp_def by (cases "p = F \<or> q = T", simp_all add: imp_def, cases p) simp_all
   553 
   576 
   554 definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   577 definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   555   where
   578   where
   556     "iff p q =
   579     "iff p q =
   557       (if (p = q) then T
   580       (if p = q then T
   558        else if (p = not q \<or> not p = q) then F
   581        else if p = not q \<or> not p = q then F
   559        else if p = F then not q
   582        else if p = F then not q
   560        else if q = F then not p
   583        else if q = F then not p
   561        else if p = T then q
   584        else if p = T then q
   562        else if q = T then p
   585        else if q = T then p
   563        else Iff p q)"
   586        else Iff p q)"
   596 | "simpfm p = p"
   619 | "simpfm p = p"
   597   by pat_completeness auto
   620   by pat_completeness auto
   598 termination by (relation "measure fmsize") auto
   621 termination by (relation "measure fmsize") auto
   599 
   622 
   600 lemma simpfm: "Ifm bbs bs (simpfm p) = Ifm bbs bs p"
   623 lemma simpfm: "Ifm bbs bs (simpfm p) = Ifm bbs bs p"
   601 proof(induct p rule: simpfm.induct)
   624 proof (induct p rule: simpfm.induct)
   602   case (6 a)
   625   case (6 a)
   603   let ?sa = "simpnum a"
   626   let ?sa = "simpnum a"
   604   from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
   627   from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
   605   { fix v assume "?sa = C v" hence ?case using sa by simp }
   628   { fix v assume "?sa = C v" hence ?case using sa by simp }
   606   moreover {
   629   moreover {
   791 
   814 
   792 lemma zsplit0_I:
   815 lemma zsplit0_I:
   793   shows "\<And>n a. zsplit0 t = (n,a) \<Longrightarrow> (Inum ((x::int) #bs) (CN 0 n a) = Inum (x #bs) t) \<and> numbound0 a"
   816   shows "\<And>n a. zsplit0 t = (n,a) \<Longrightarrow> (Inum ((x::int) #bs) (CN 0 n a) = Inum (x #bs) t) \<and> numbound0 a"
   794   (is "\<And>n a. ?S t = (n,a) \<Longrightarrow> (?I x (CN 0 n a) = ?I x t) \<and> ?N a")
   817   (is "\<And>n a. ?S t = (n,a) \<Longrightarrow> (?I x (CN 0 n a) = ?I x t) \<and> ?N a")
   795 proof (induct t rule: zsplit0.induct)
   818 proof (induct t rule: zsplit0.induct)
   796   case (1 c n a) thus ?case by auto
   819   case (1 c n a)
   797 next
   820   then show ?case by auto
   798   case (2 m n a) thus ?case by (cases "m=0") auto
   821 next
       
   822   case (2 m n a)
       
   823   then show ?case by (cases "m = 0") auto
   799 next
   824 next
   800   case (3 m i a n a')
   825   case (3 m i a n a')
   801   let ?j = "fst (zsplit0 a)"
   826   let ?j = "fst (zsplit0 a)"
   802   let ?b = "snd (zsplit0 a)"
   827   let ?b = "snd (zsplit0 a)"
   803   have abj: "zsplit0 a = (?j,?b)" by simp
   828   have abj: "zsplit0 a = (?j, ?b)" by simp
   804   {assume "m\<noteq>0"
   829   {
   805     with 3(1)[OF abj] 3(2) have ?case by (auto simp add: Let_def split_def)}
   830     assume "m \<noteq> 0"
       
   831     with 3(1)[OF abj] 3(2) have ?case
       
   832       by (auto simp add: Let_def split_def)
       
   833   }
   806   moreover
   834   moreover
   807   {assume m0: "m =0"
   835   {
       
   836     assume m0: "m = 0"
   808     with abj have th: "a'=?b \<and> n=i+?j" using 3
   837     with abj have th: "a'=?b \<and> n=i+?j" using 3
   809       by (simp add: Let_def split_def)
   838       by (simp add: Let_def split_def)
   810     from abj 3 m0 have th2: "(?I x (CN 0 ?j ?b) = ?I x a) \<and> ?N ?b" by blast
   839     from abj 3 m0 have th2: "(?I x (CN 0 ?j ?b) = ?I x a) \<and> ?N ?b"
   811     from th have "?I x (CN 0 n a') = ?I x (CN 0 (i+?j) ?b)" by simp
   840       by blast
   812     also from th2 have "\<dots> = ?I x (CN 0 i (CN 0 ?j ?b))" by (simp add: distrib_right)
   841     from th have "?I x (CN 0 n a') = ?I x (CN 0 (i+?j) ?b)"
   813   finally have "?I x (CN 0 n a') = ?I  x (CN 0 i a)" using th2 by simp
   842       by simp
   814   with th2 th have ?case using m0 by blast}
   843     also from th2 have "\<dots> = ?I x (CN 0 i (CN 0 ?j ?b))"
   815 ultimately show ?case by blast
   844       by (simp add: distrib_right)
       
   845     finally have "?I x (CN 0 n a') = ?I  x (CN 0 i a)"
       
   846       using th2 by simp
       
   847     with th2 th have ?case using m0
       
   848       by blast
       
   849   }
       
   850   ultimately show ?case by blast
   816 next
   851 next
   817   case (4 t n a)
   852   case (4 t n a)
   818   let ?nt = "fst (zsplit0 t)"
   853   let ?nt = "fst (zsplit0 t)"
   819   let ?at = "snd (zsplit0 t)"
   854   let ?at = "snd (zsplit0 t)"
   820   have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \<and> n=-?nt" using 4
   855   have abj: "zsplit0 t = (?nt,?at)" by simp
   821     by (simp add: Let_def split_def)
   856   then have th: "a=Neg ?at \<and> n=-?nt"
   822   from abj 4 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
   857     using 4 by (simp add: Let_def split_def)
   823   from th2[simplified] th[simplified] show ?case by simp
   858   from abj 4 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at"
       
   859     by blast
       
   860   from th2[simplified] th[simplified] show ?case
       
   861     by simp
   824 next
   862 next
   825   case (5 s t n a)
   863   case (5 s t n a)
   826   let ?ns = "fst (zsplit0 s)"
   864   let ?ns = "fst (zsplit0 s)"
   827   let ?as = "snd (zsplit0 s)"
   865   let ?as = "snd (zsplit0 s)"
   828   let ?nt = "fst (zsplit0 t)"
   866   let ?nt = "fst (zsplit0 t)"
   829   let ?at = "snd (zsplit0 t)"
   867   let ?at = "snd (zsplit0 t)"
   830   have abjs: "zsplit0 s = (?ns,?as)" by simp
   868   have abjs: "zsplit0 s = (?ns, ?as)"
   831   moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp
   869     by simp
   832   ultimately have th: "a=Add ?as ?at \<and> n=?ns + ?nt" using 5
   870   moreover have abjt: "zsplit0 t = (?nt, ?at)"
   833     by (simp add: Let_def split_def)
   871     by simp
   834   from abjs[symmetric] have bluddy: "\<exists>x y. (x,y) = zsplit0 s" by blast
   872   ultimately have th: "a=Add ?as ?at \<and> n=?ns + ?nt"
   835   from 5 have "(\<exists>x y. (x,y) = zsplit0 s) \<longrightarrow> (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \<and> numbound0 xb)" by auto
   873     using 5 by (simp add: Let_def split_def)
   836   with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
   874   from abjs[symmetric] have bluddy: "\<exists>x y. (x,y) = zsplit0 s"
   837   from abjs 5 have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
   875     by blast
       
   876   from 5 have "(\<exists>x y. (x, y) = zsplit0 s) \<longrightarrow>
       
   877     (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \<and> numbound0 xb)"
       
   878     by auto
       
   879   with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at"
       
   880     by blast
       
   881   from abjs 5 have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as"
       
   882     by blast
   838   from th3[simplified] th2[simplified] th[simplified] show ?case
   883   from th3[simplified] th2[simplified] th[simplified] show ?case
   839     by (simp add: distrib_right)
   884     by (simp add: distrib_right)
   840 next
   885 next
   841   case (6 s t n a)
   886   case (6 s t n a)
   842   let ?ns = "fst (zsplit0 s)"
   887   let ?ns = "fst (zsplit0 s)"
   843   let ?as = "snd (zsplit0 s)"
   888   let ?as = "snd (zsplit0 s)"
   844   let ?nt = "fst (zsplit0 t)"
   889   let ?nt = "fst (zsplit0 t)"
   845   let ?at = "snd (zsplit0 t)"
   890   let ?at = "snd (zsplit0 t)"
   846   have abjs: "zsplit0 s = (?ns,?as)" by simp
   891   have abjs: "zsplit0 s = (?ns, ?as)"
   847   moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp
   892     by simp
   848   ultimately have th: "a=Sub ?as ?at \<and> n=?ns - ?nt" using 6
   893   moreover have abjt: "zsplit0 t = (?nt, ?at)"
   849     by (simp add: Let_def split_def)
   894     by simp
   850   from abjs[symmetric] have bluddy: "\<exists>x y. (x,y) = zsplit0 s" by blast
   895   ultimately have th: "a=Sub ?as ?at \<and> n=?ns - ?nt"
       
   896     using 6 by (simp add: Let_def split_def)
       
   897   from abjs[symmetric] have bluddy: "\<exists>x y. (x,y) = zsplit0 s"
       
   898     by blast
   851   from 6 have "(\<exists>x y. (x,y) = zsplit0 s) \<longrightarrow>
   899   from 6 have "(\<exists>x y. (x,y) = zsplit0 s) \<longrightarrow>
   852     (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \<and> numbound0 xb)"
   900     (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \<and> numbound0 xb)"
   853     by auto
   901     by auto
   854   with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
   902   with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at"
   855   from abjs 6 have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
   903     by blast
       
   904   from abjs 6 have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as"
       
   905     by blast
   856   from th3[simplified] th2[simplified] th[simplified] show ?case
   906   from th3[simplified] th2[simplified] th[simplified] show ?case
   857     by (simp add: left_diff_distrib)
   907     by (simp add: left_diff_distrib)
   858 next
   908 next
   859   case (7 i t n a)
   909   case (7 i t n a)
   860   let ?nt = "fst (zsplit0 t)"
   910   let ?nt = "fst (zsplit0 t)"
   861   let ?at = "snd (zsplit0 t)"
   911   let ?at = "snd (zsplit0 t)"
   862   have abj: "zsplit0 t = (?nt,?at)" by simp
   912   have abj: "zsplit0 t = (?nt,?at)"
   863   hence th: "a=Mul i ?at \<and> n=i*?nt" using 7
   913     by simp
   864     by (simp add: Let_def split_def)
   914   then have th: "a=Mul i ?at \<and> n=i*?nt"
   865   from abj 7 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
   915     using 7 by (simp add: Let_def split_def)
   866   hence "?I x (Mul i t) = i * ?I x (CN 0 ?nt ?at)" by simp
   916   from abj 7 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at"
   867   also have "\<dots> = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: distrib_left)
   917     by blast
   868   finally show ?case using th th2 by simp
   918   then have "?I x (Mul i t) = i * ?I x (CN 0 ?nt ?at)"
       
   919     by simp
       
   920   also have "\<dots> = ?I x (CN 0 (i*?nt) (Mul i ?at))"
       
   921     by (simp add: distrib_left)
       
   922   finally show ?case using th th2
       
   923     by simp
   869 qed
   924 qed
   870 
   925 
   871 consts iszlfm :: "fm \<Rightarrow> bool"  -- {* Linearity test for fm *}
   926 consts iszlfm :: "fm \<Rightarrow> bool"  -- {* Linearity test for fm *}
   872 recdef iszlfm "measure size"
   927 recdef iszlfm "measure size"
   873   "iszlfm (And p q) = (iszlfm p \<and> iszlfm q)"
   928   "iszlfm (And p q) = (iszlfm p \<and> iszlfm q)"
   947   using qfp
  1002   using qfp
   948 proof (induct p rule: zlfm.induct)
  1003 proof (induct p rule: zlfm.induct)
   949   case (5 a)
  1004   case (5 a)
   950   let ?c = "fst (zsplit0 a)"
  1005   let ?c = "fst (zsplit0 a)"
   951   let ?r = "snd (zsplit0 a)"
  1006   let ?r = "snd (zsplit0 a)"
   952   have spl: "zsplit0 a = (?c,?r)" by simp
  1007   have spl: "zsplit0 a = (?c, ?r)"
       
  1008     by simp
   953   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1009   from zsplit0_I[OF spl, where x="i" and bs="bs"]
   954   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1010   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1011     by auto
   955   let ?N = "\<lambda>t. Inum (i#bs) t"
  1012   let ?N = "\<lambda>t. Inum (i#bs) t"
   956   from 5 Ia nb  show ?case
  1013   from 5 Ia nb  show ?case
   957     apply (auto simp add: Let_def split_def algebra_simps)
  1014     apply (auto simp add: Let_def split_def algebra_simps)
   958     apply (cases "?r", auto)
  1015     apply (cases "?r")
   959     apply (case_tac nat, auto)
  1016     apply auto
       
  1017     apply (case_tac nat)
       
  1018     apply auto
   960     done
  1019     done
   961 next
  1020 next
   962   case (6 a)
  1021   case (6 a)
   963   let ?c = "fst (zsplit0 a)"
  1022   let ?c = "fst (zsplit0 a)"
   964   let ?r = "snd (zsplit0 a)"
  1023   let ?r = "snd (zsplit0 a)"
   965   have spl: "zsplit0 a = (?c,?r)" by simp
  1024   have spl: "zsplit0 a = (?c, ?r)"
       
  1025     by simp
   966   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1026   from zsplit0_I[OF spl, where x="i" and bs="bs"]
   967   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1027   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1028     by auto
   968   let ?N = "\<lambda>t. Inum (i#bs) t"
  1029   let ?N = "\<lambda>t. Inum (i#bs) t"
   969   from 6 Ia nb show ?case
  1030   from 6 Ia nb show ?case
   970     apply (auto simp add: Let_def split_def algebra_simps)
  1031     apply (auto simp add: Let_def split_def algebra_simps)
   971     apply (cases "?r", auto)
  1032     apply (cases "?r")
   972     apply (case_tac nat, auto)
  1033     apply auto
       
  1034     apply (case_tac nat)
       
  1035     apply auto
   973     done
  1036     done
   974 next
  1037 next
   975   case (7 a)
  1038   case (7 a)
   976   let ?c = "fst (zsplit0 a)"
  1039   let ?c = "fst (zsplit0 a)"
   977   let ?r = "snd (zsplit0 a)"
  1040   let ?r = "snd (zsplit0 a)"
   978   have spl: "zsplit0 a = (?c,?r)" by simp
  1041   have spl: "zsplit0 a = (?c, ?r)"
       
  1042     by simp
   979   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1043   from zsplit0_I[OF spl, where x="i" and bs="bs"]
   980   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1044   have Ia: "Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1045     by auto
   981   let ?N = "\<lambda>t. Inum (i#bs) t"
  1046   let ?N = "\<lambda>t. Inum (i#bs) t"
   982   from 7 Ia nb show ?case
  1047   from 7 Ia nb show ?case
   983     apply (auto simp add: Let_def split_def algebra_simps)
  1048     apply (auto simp add: Let_def split_def algebra_simps)
   984     apply (cases "?r", auto)
  1049     apply (cases "?r")
   985     apply (case_tac nat, auto)
  1050     apply auto
       
  1051     apply (case_tac nat)
       
  1052     apply auto
   986     done
  1053     done
   987 next
  1054 next
   988   case (8 a)
  1055   case (8 a)
   989   let ?c = "fst (zsplit0 a)"
  1056   let ?c = "fst (zsplit0 a)"
   990   let ?r = "snd (zsplit0 a)"
  1057   let ?r = "snd (zsplit0 a)"
   991   have spl: "zsplit0 a = (?c,?r)" by simp
  1058   have spl: "zsplit0 a = (?c, ?r)"
       
  1059     by simp
   992   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1060   from zsplit0_I[OF spl, where x="i" and bs="bs"]
   993   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1061   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1062     by auto
   994   let ?N = "\<lambda>t. Inum (i#bs) t"
  1063   let ?N = "\<lambda>t. Inum (i#bs) t"
   995   from 8 Ia nb  show ?case
  1064   from 8 Ia nb show ?case
   996     apply (auto simp add: Let_def split_def algebra_simps)
  1065     apply (auto simp add: Let_def split_def algebra_simps)
   997     apply (cases "?r", auto)
  1066     apply (cases "?r")
   998     apply (case_tac nat, auto)
  1067     apply auto
       
  1068     apply (case_tac nat)
       
  1069     apply auto
   999     done
  1070     done
  1000 next
  1071 next
  1001   case (9 a)
  1072   case (9 a)
  1002   let ?c = "fst (zsplit0 a)"
  1073   let ?c = "fst (zsplit0 a)"
  1003   let ?r = "snd (zsplit0 a)"
  1074   let ?r = "snd (zsplit0 a)"
  1004   have spl: "zsplit0 a = (?c,?r)" by simp
  1075   have spl: "zsplit0 a = (?c, ?r)"
       
  1076     by simp
  1005   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1077   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1006   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1078   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1079     by auto
  1007   let ?N = "\<lambda>t. Inum (i#bs) t"
  1080   let ?N = "\<lambda>t. Inum (i#bs) t"
  1008   from 9 Ia nb  show ?case
  1081   from 9 Ia nb show ?case
  1009     apply (auto simp add: Let_def split_def algebra_simps)
  1082     apply (auto simp add: Let_def split_def algebra_simps)
  1010     apply (cases "?r", auto)
  1083     apply (cases "?r")
  1011     apply (case_tac nat, auto)
  1084     apply auto
       
  1085     apply (case_tac nat)
       
  1086     apply auto
  1012     done
  1087     done
  1013 next
  1088 next
  1014   case (10 a)
  1089   case (10 a)
  1015   let ?c = "fst (zsplit0 a)"
  1090   let ?c = "fst (zsplit0 a)"
  1016   let ?r = "snd (zsplit0 a)"
  1091   let ?r = "snd (zsplit0 a)"
  1017   have spl: "zsplit0 a = (?c,?r)" by simp
  1092   have spl: "zsplit0 a = (?c, ?r)"
       
  1093     by simp
  1018   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1094   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1019   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1095   have Ia: "Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1096     by auto
  1020   let ?N = "\<lambda>t. Inum (i#bs) t"
  1097   let ?N = "\<lambda>t. Inum (i#bs) t"
  1021   from 10 Ia nb  show ?case
  1098   from 10 Ia nb show ?case
  1022     apply (auto simp add: Let_def split_def algebra_simps)
  1099     apply (auto simp add: Let_def split_def algebra_simps)
  1023     apply (cases "?r",auto)
  1100     apply (cases "?r")
  1024     apply (case_tac nat, auto)
  1101     apply auto
       
  1102     apply (case_tac nat)
       
  1103     apply auto
  1025     done
  1104     done
  1026 next
  1105 next
  1027   case (11 j a)
  1106   case (11 j a)
  1028   let ?c = "fst (zsplit0 a)"
  1107   let ?c = "fst (zsplit0 a)"
  1029   let ?r = "snd (zsplit0 a)"
  1108   let ?r = "snd (zsplit0 a)"
  1030   have spl: "zsplit0 a = (?c,?r)" by simp
  1109   have spl: "zsplit0 a = (?c,?r)"
       
  1110     by simp
  1031   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1111   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1032   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1112   have Ia: "Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1113     by auto
  1033   let ?N = "\<lambda>t. Inum (i#bs) t"
  1114   let ?N = "\<lambda>t. Inum (i#bs) t"
  1034   have "j=0 \<or> (j\<noteq>0 \<and> ?c = 0) \<or> (j\<noteq>0 \<and> ?c >0) \<or> (j\<noteq> 0 \<and> ?c<0)" by arith
  1115   have "j = 0 \<or> (j \<noteq> 0 \<and> ?c = 0) \<or> (j \<noteq> 0 \<and> ?c > 0) \<or> (j \<noteq> 0 \<and> ?c < 0)"
       
  1116     by arith
  1035   moreover
  1117   moreover
  1036   {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def)
  1118   {
  1037     hence ?case using 11 `j = 0` by (simp del: zlfm.simps) }
  1119     assume "j = 0"
       
  1120     then have z: "zlfm (Dvd j a) = (zlfm (Eq a))"
       
  1121       by (simp add: Let_def)
       
  1122     then have ?case using 11 `j = 0`
       
  1123       by (simp del: zlfm.simps)
       
  1124   }
  1038   moreover
  1125   moreover
  1039   {assume "?c=0" and "j\<noteq>0" hence ?case
  1126   {
       
  1127     assume "?c = 0" and "j \<noteq> 0"
       
  1128     then have ?case
  1040       using zsplit0_I[OF spl, where x="i" and bs="bs"]
  1129       using zsplit0_I[OF spl, where x="i" and bs="bs"]
  1041     apply (auto simp add: Let_def split_def algebra_simps)
  1130     apply (auto simp add: Let_def split_def algebra_simps)
  1042     apply (cases "?r",auto)
  1131     apply (cases "?r")
  1043     apply (case_tac nat, auto)
  1132     apply auto
  1044     done}
  1133     apply (case_tac nat)
       
  1134     apply auto
       
  1135     done
       
  1136   }
  1045   moreover
  1137   moreover
  1046   {assume cp: "?c > 0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))"
  1138   {
       
  1139     assume cp: "?c > 0" and jnz: "j \<noteq> 0"
       
  1140     then have l: "?L (?l (Dvd j a))"
  1047       by (simp add: nb Let_def split_def)
  1141       by (simp add: nb Let_def split_def)
  1048     hence ?case using Ia cp jnz by (simp add: Let_def split_def)}
  1142     then have ?case
       
  1143       using Ia cp jnz by (simp add: Let_def split_def)
       
  1144   }
  1049   moreover
  1145   moreover
  1050   {assume cn: "?c < 0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))"
  1146   { 
       
  1147     assume cn: "?c < 0" and jnz: "j \<noteq> 0"
       
  1148     then have l: "?L (?l (Dvd j a))"
  1051       by (simp add: nb Let_def split_def)
  1149       by (simp add: nb Let_def split_def)
  1052     hence ?case using Ia cn jnz dvd_minus_iff[of "abs j" "?c*i + ?N ?r" ]
  1150     then have ?case
  1053       by (simp add: Let_def split_def) }
  1151       using Ia cn jnz dvd_minus_iff[of "abs j" "?c*i + ?N ?r"]
       
  1152       by (simp add: Let_def split_def)
       
  1153   }
  1054   ultimately show ?case by blast
  1154   ultimately show ?case by blast
  1055 next
  1155 next
  1056   case (12 j a)
  1156   case (12 j a)
  1057   let ?c = "fst (zsplit0 a)"
  1157   let ?c = "fst (zsplit0 a)"
  1058   let ?r = "snd (zsplit0 a)"
  1158   let ?r = "snd (zsplit0 a)"
  1059   have spl: "zsplit0 a = (?c,?r)" by simp
  1159   have spl: "zsplit0 a = (?c, ?r)"
       
  1160     by simp
  1060   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1161   from zsplit0_I[OF spl, where x="i" and bs="bs"]
  1061   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
  1162   have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
       
  1163     by auto
  1062   let ?N = "\<lambda>t. Inum (i#bs) t"
  1164   let ?N = "\<lambda>t. Inum (i#bs) t"
  1063   have "j=0 \<or> (j\<noteq>0 \<and> ?c = 0) \<or> (j\<noteq>0 \<and> ?c >0) \<or> (j\<noteq> 0 \<and> ?c<0)" by arith
  1165   have "j = 0 \<or> (j \<noteq> 0 \<and> ?c = 0) \<or> (j \<noteq> 0 \<and> ?c > 0) \<or> (j \<noteq> 0 \<and> ?c < 0)"
       
  1166     by arith
  1064   moreover
  1167   moreover
  1065   {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def)
  1168   {
  1066     hence ?case using assms 12 `j = 0` by (simp del: zlfm.simps)}
  1169     assume "j = 0"
       
  1170     then have z: "zlfm (NDvd j a) = (zlfm (NEq a))"
       
  1171       by (simp add: Let_def)
       
  1172     then have ?case
       
  1173       using assms 12 `j = 0` by (simp del: zlfm.simps)
       
  1174   }
  1067   moreover
  1175   moreover
  1068   {assume "?c=0" and "j\<noteq>0" hence ?case
  1176   {
       
  1177     assume "?c = 0" and "j \<noteq> 0"
       
  1178     then have ?case
  1069       using zsplit0_I[OF spl, where x="i" and bs="bs"]
  1179       using zsplit0_I[OF spl, where x="i" and bs="bs"]
  1070     apply (auto simp add: Let_def split_def algebra_simps)
  1180     apply (auto simp add: Let_def split_def algebra_simps)
  1071     apply (cases "?r",auto)
  1181     apply (cases "?r")
  1072     apply (case_tac nat, auto)
  1182     apply auto
  1073     done}
  1183     apply (case_tac nat)
       
  1184     apply auto
       
  1185     done
       
  1186   }
  1074   moreover
  1187   moreover
  1075   {assume cp: "?c > 0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))"
  1188   {
       
  1189     assume cp: "?c > 0" and jnz: "j \<noteq> 0"
       
  1190     then have l: "?L (?l (Dvd j a))"
  1076       by (simp add: nb Let_def split_def)
  1191       by (simp add: nb Let_def split_def)
  1077     hence ?case using Ia cp jnz by (simp add: Let_def split_def) }
  1192     then have ?case using Ia cp jnz
       
  1193       by (simp add: Let_def split_def)
       
  1194   }
  1078   moreover
  1195   moreover
  1079   {assume cn: "?c < 0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))"
  1196   {
       
  1197     assume cn: "?c < 0" and jnz: "j \<noteq> 0"
       
  1198     then have l: "?L (?l (Dvd j a))"
  1080       by (simp add: nb Let_def split_def)
  1199       by (simp add: nb Let_def split_def)
  1081     hence ?case using Ia cn jnz dvd_minus_iff[of "abs j" "?c*i + ?N ?r"]
  1200     then have ?case
  1082       by (simp add: Let_def split_def)}
  1201       using Ia cn jnz dvd_minus_iff[of "abs j" "?c*i + ?N ?r"]
       
  1202       by (simp add: Let_def split_def)
       
  1203   }
  1083   ultimately show ?case by blast
  1204   ultimately show ?case by blast
  1084 qed auto
  1205 qed auto
  1085 
  1206 
  1086 consts minusinf :: "fm \<Rightarrow> fm" -- {* Virtual substitution of @{text "-\<infinity>"} *}
  1207 consts minusinf :: "fm \<Rightarrow> fm" -- {* Virtual substitution of @{text "-\<infinity>"} *}
  1087 recdef minusinf "measure size"
  1208 recdef minusinf "measure size"
  1131     and d: "d dvd d'"
  1252     and d: "d dvd d'"
  1132     and ad: "d_\<delta> p d"
  1253     and ad: "d_\<delta> p d"
  1133   shows "d_\<delta> p d'"
  1254   shows "d_\<delta> p d'"
  1134   using lin ad d
  1255   using lin ad d
  1135 proof (induct p rule: iszlfm.induct)
  1256 proof (induct p rule: iszlfm.induct)
  1136   case (9 i c e)  thus ?case using d
  1257   case (9 i c e)
       
  1258   then show ?case using d
  1137     by (simp add: dvd_trans[of "i" "d" "d'"])
  1259     by (simp add: dvd_trans[of "i" "d" "d'"])
  1138 next
  1260 next
  1139   case (10 i c e) thus ?case using d
  1261   case (10 i c e)
       
  1262   then show ?case using d
  1140     by (simp add: dvd_trans[of "i" "d" "d'"])
  1263     by (simp add: dvd_trans[of "i" "d" "d'"])
  1141 qed simp_all
  1264 qed simp_all
  1142 
  1265 
  1143 lemma \<delta>:
  1266 lemma \<delta>:
  1144   assumes lin:"iszlfm p"
  1267   assumes lin:"iszlfm p"
  1145   shows "d_\<delta> p (\<delta> p) \<and> \<delta> p >0"
  1268   shows "d_\<delta> p (\<delta> p) \<and> \<delta> p >0"
  1146   using lin
  1269   using lin
  1147 proof (induct p rule: iszlfm.induct)
  1270 proof (induct p rule: iszlfm.induct)
  1148   case (1 p q)
  1271   case (1 p q)
  1149   let ?d = "\<delta> (And p q)"
  1272   let ?d = "\<delta> (And p q)"
  1150   from 1 lcm_pos_int have dp: "?d >0" by simp
  1273   from 1 lcm_pos_int have dp: "?d > 0"
  1151   have d1: "\<delta> p dvd \<delta> (And p q)" using 1 by simp
  1274     by simp
  1152   hence th: "d_\<delta> p ?d" using delta_mono 1(2,3) by(simp only: iszlfm.simps)
  1275   have d1: "\<delta> p dvd \<delta> (And p q)"
  1153   have "\<delta> q dvd \<delta> (And p q)" using 1 by simp
  1276     using 1 by simp
  1154   hence th': "d_\<delta> q ?d" using delta_mono 1 by(simp only: iszlfm.simps)
  1277   then have th: "d_\<delta> p ?d"
  1155   from th th' dp show ?case by simp
  1278     using delta_mono 1(2,3) by (simp only: iszlfm.simps)
       
  1279   have "\<delta> q dvd \<delta> (And p q)"
       
  1280     using 1 by simp
       
  1281   then have th': "d_\<delta> q ?d"
       
  1282     using delta_mono 1 by (simp only: iszlfm.simps)
       
  1283   from th th' dp show ?case
       
  1284     by simp
  1156 next
  1285 next
  1157   case (2 p q)
  1286   case (2 p q)
  1158   let ?d = "\<delta> (And p q)"
  1287   let ?d = "\<delta> (And p q)"
  1159   from 2 lcm_pos_int have dp: "?d >0" by simp
  1288   from 2 lcm_pos_int have dp: "?d > 0"
  1160   have "\<delta> p dvd \<delta> (And p q)" using 2 by simp
  1289     by simp
  1161   hence th: "d_\<delta> p ?d" using delta_mono 2 by(simp only: iszlfm.simps)
  1290   have "\<delta> p dvd \<delta> (And p q)"
  1162   have "\<delta> q dvd \<delta> (And p q)" using 2 by simp
  1291     using 2 by simp
  1163   hence th': "d_\<delta> q ?d" using delta_mono 2 by(simp only: iszlfm.simps)
  1292   then have th: "d_\<delta> p ?d"
  1164   from th th' dp show ?case by simp
  1293     using delta_mono 2 by (simp only: iszlfm.simps)
       
  1294   have "\<delta> q dvd \<delta> (And p q)"
       
  1295     using 2 by simp
       
  1296   then have th': "d_\<delta> q ?d"
       
  1297     using delta_mono 2 by (simp only: iszlfm.simps)
       
  1298   from th th' dp show ?case
       
  1299     by simp
  1165 qed simp_all
  1300 qed simp_all
  1166 
  1301 
  1167 
  1302 
  1168 consts a_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> fm"  -- {* adjust the coeffitients of a formula *}
  1303 consts a_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> fm"  -- {* adjust the coeffitients of a formula *}
  1169 recdef a_\<beta> "measure size"
  1304 recdef a_\<beta> "measure size"
  1245   "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))"
  1380   "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))"
  1246   "mirror p = p"
  1381   "mirror p = p"
  1247 
  1382 
  1248 text {* Lemmas for the correctness of @{text "\<sigma>_\<rho>"} *}
  1383 text {* Lemmas for the correctness of @{text "\<sigma>_\<rho>"} *}
  1249 
  1384 
  1250 lemma dvd1_eq1: "x >0 \<Longrightarrow> (x::int) dvd 1 = (x = 1)"
  1385 lemma dvd1_eq1:
       
  1386   fixes x :: int
       
  1387   shows "x > 0 \<Longrightarrow> x dvd 1 \<longleftrightarrow> x = 1"
  1251   by simp
  1388   by simp
  1252 
  1389 
  1253 lemma minusinf_inf:
  1390 lemma minusinf_inf:
  1254   assumes linp: "iszlfm p"
  1391   assumes linp: "iszlfm p"
  1255     and u: "d_\<beta> p 1"
  1392     and u: "d_\<beta> p 1"
  1256   shows "\<exists>(z::int). \<forall>x < z. Ifm bbs (x#bs) (minusinf p) = Ifm bbs (x#bs) p"
  1393   shows "\<exists>(z::int). \<forall>x < z. Ifm bbs (x#bs) (minusinf p) = Ifm bbs (x#bs) p"
  1257   (is "?P p" is "\<exists>(z::int). \<forall>x < z. ?I x (?M p) = ?I x p")
  1394   (is "?P p" is "\<exists>(z::int). \<forall>x < z. ?I x (?M p) = ?I x p")
  1258   using linp u
  1395   using linp u
  1259 proof (induct p rule: minusinf.induct)
  1396 proof (induct p rule: minusinf.induct)
  1260   case (1 p q) thus ?case
  1397   case (1 p q)
       
  1398   then show ?case
  1261     by auto (rule_tac x="min z za" in exI,simp)
  1399     by auto (rule_tac x="min z za" in exI,simp)
  1262 next
  1400 next
  1263   case (2 p q) thus ?case
  1401   case (2 p q)
       
  1402   then show ?case
  1264     by auto (rule_tac x="min z za" in exI,simp)
  1403     by auto (rule_tac x="min z za" in exI,simp)
  1265 next
  1404 next
  1266   case (3 c e) hence c1: "c=1" and nb: "numbound0 e" by simp_all
  1405   case (3 c e)
       
  1406   then have c1: "c = 1" and nb: "numbound0 e"
       
  1407     by simp_all
  1267   fix a
  1408   fix a
  1268   from 3 have "\<forall>x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \<noteq> 0"
  1409   from 3 have "\<forall>x<(- Inum (a#bs) e). c * x + Inum (x # bs) e \<noteq> 0"
  1269   proof(clarsimp)
  1410   proof clarsimp
  1270     fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0"
  1411     fix x
       
  1412     assume "x < (- Inum (a#bs) e)" and "x + Inum (x#bs) e = 0"
  1271     with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"]
  1413     with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"]
  1272     show "False" by simp
  1414     show False by simp
  1273   qed
  1415   qed
  1274   thus ?case by auto
  1416   then show ?case by auto
  1275 next
  1417 next
  1276   case (4 c e) hence c1: "c=1" and nb: "numbound0 e" by simp_all
  1418   case (4 c e)
       
  1419   then have c1: "c = 1" and nb: "numbound0 e"
       
  1420     by simp_all
  1277   fix a
  1421   fix a
  1278   from 4 have "\<forall>x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \<noteq> 0"
  1422   from 4 have "\<forall>x < (- Inum (a#bs) e). c*x + Inum (x#bs) e \<noteq> 0"
  1279   proof(clarsimp)
  1423   proof(clarsimp)
  1280     fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0"
  1424     fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0"
  1281     with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"]
  1425     with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"]
  1282     show "False" by simp
  1426     show "False" by simp
  1283   qed
  1427   qed