# HG changeset patch # User haftmann # Date 1233676241 -3600 # Node ID 1b80ebe713a48859497a72e5da02632e9bcef6cf # Parent 23bf900a21db45c1e9f62dafd479bbdf3f9045bc established session HOL-Reflection diff -r 23bf900a21db -r 1b80ebe713a4 NEWS --- a/NEWS Tue Feb 03 16:50:40 2009 +0100 +++ b/NEWS Tue Feb 03 16:50:41 2009 +0100 @@ -193,7 +193,8 @@ *** HOL *** -* Theory "Reflection" now resides in HOL/Library. +* Theory "Reflection" now resides in HOL/Library. Common reflection examples +(Cooper, MIR, Ferrack) now in distinct session directory HOL/Reflection. * Entry point to Word library now simply named "Word". INCOMPATIBILITY. diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/IsaMakefile --- a/src/HOL/IsaMakefile Tue Feb 03 16:50:40 2009 +0100 +++ b/src/HOL/IsaMakefile Tue Feb 03 16:50:41 2009 +0100 @@ -36,6 +36,7 @@ HOL-Nominal-Examples \ HOL-NumberTheory \ HOL-Prolog \ + HOL-Reflection \ HOL-SET-Protocol \ HOL-SizeChange \ HOL-Statespace \ @@ -678,6 +679,21 @@ @$(ISABELLE_TOOL) usedir $(OUT)/HOL Prolog +## HOL-Reflection + +HOL-Reflection: HOL $(LOG)/HOL-Reflection.gz + +$(LOG)/HOL-Reflection.gz: $(OUT)/HOL \ + Reflection/Cooper.thy \ + Reflection/cooper_tac.ML \ + Reflection/Ferrack.thy \ + Reflection/ferrack_tac.ML \ + Reflection/MIR.thy \ + Reflection/mir_tac.ML \ + Reflection/ROOT.ML + @$(ISABELLE_TOOL) usedir $(OUT)/HOL Reflection + + ## HOL-W0 HOL-W0: HOL $(LOG)/HOL-W0.gz @@ -812,7 +828,6 @@ ex/Numeral.thy ex/PER.thy ex/PresburgerEx.thy ex/Primrec.thy \ ex/Quickcheck_Examples.thy \ ex/ReflectionEx.thy ex/ROOT.ML ex/Recdefs.thy ex/Records.thy \ - ex/Reflected_Presburger.thy ex/coopertac.ML \ ex/Refute_Examples.thy ex/SAT_Examples.thy ex/SVC_Oracle.thy \ ex/Subarray.thy ex/Sublist.thy \ ex/Sudoku.thy ex/Tarski.thy ex/Termination.thy ex/Term_Of_Syntax.thy \ @@ -822,10 +837,7 @@ ex/ImperativeQuicksort.thy \ ex/BigO_Complex.thy \ ex/Arithmetic_Series_Complex.thy ex/HarmonicSeries.thy \ - ex/Sqrt.thy \ - ex/Sqrt_Script.thy ex/MIR.thy ex/mirtac.ML \ - ex/ReflectedFerrack.thy \ - ex/linrtac.ML + ex/Sqrt.thy ex/Sqrt_Script.thy @$(ISABELLE_TOOL) usedir $(OUT)/HOL ex diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/Reflection/Cooper.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Reflection/Cooper.thy Tue Feb 03 16:50:41 2009 +0100 @@ -0,0 +1,2174 @@ +(* Title: HOL/Reflection/Cooper.thy + Author: Amine Chaieb +*) + +theory Cooper +imports Complex_Main Efficient_Nat +uses ("cooper_tac.ML") +begin + +function iupt :: "int \ int \ int list" where + "iupt i j = (if j < i then [] else i # iupt (i+1) j)" +by pat_completeness auto +termination by (relation "measure (\ (i, j). nat (j-i+1))") auto + +lemma iupt_set: "set (iupt i j) = {i..j}" + by (induct rule: iupt.induct) (simp add: simp_from_to) + +(* Periodicity of dvd *) + + (*********************************************************************************) + (**** SHADOW SYNTAX AND SEMANTICS ****) + (*********************************************************************************) + +datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num + | Mul int num + + (* A size for num to make inductive proofs simpler*) +primrec num_size :: "num \ nat" where + "num_size (C c) = 1" +| "num_size (Bound n) = 1" +| "num_size (Neg a) = 1 + num_size a" +| "num_size (Add a b) = 1 + num_size a + num_size b" +| "num_size (Sub a b) = 3 + num_size a + num_size b" +| "num_size (CN n c a) = 4 + num_size a" +| "num_size (Mul c a) = 1 + num_size a" + +primrec Inum :: "int list \ num \ int" where + "Inum bs (C c) = c" +| "Inum bs (Bound n) = bs!n" +| "Inum bs (CN n c a) = c * (bs!n) + (Inum bs a)" +| "Inum bs (Neg a) = -(Inum bs a)" +| "Inum bs (Add a b) = Inum bs a + Inum bs b" +| "Inum bs (Sub a b) = Inum bs a - Inum bs b" +| "Inum bs (Mul c a) = c* Inum bs a" + +datatype fm = + T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num| + NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm + | Closed nat | NClosed nat + + + (* A size for fm *) +consts fmsize :: "fm \ nat" +recdef fmsize "measure size" + "fmsize (NOT p) = 1 + fmsize p" + "fmsize (And p q) = 1 + fmsize p + fmsize q" + "fmsize (Or p q) = 1 + fmsize p + fmsize q" + "fmsize (Imp p q) = 3 + fmsize p + fmsize q" + "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" + "fmsize (E p) = 1 + fmsize p" + "fmsize (A p) = 4+ fmsize p" + "fmsize (Dvd i t) = 2" + "fmsize (NDvd i t) = 2" + "fmsize p = 1" + (* several lemmas about fmsize *) +lemma fmsize_pos: "fmsize p > 0" +by (induct p rule: fmsize.induct) simp_all + + (* Semantics of formulae (fm) *) +consts Ifm ::"bool list \ int list \ fm \ bool" +primrec + "Ifm bbs bs T = True" + "Ifm bbs bs F = False" + "Ifm bbs bs (Lt a) = (Inum bs a < 0)" + "Ifm bbs bs (Gt a) = (Inum bs a > 0)" + "Ifm bbs bs (Le a) = (Inum bs a \ 0)" + "Ifm bbs bs (Ge a) = (Inum bs a \ 0)" + "Ifm bbs bs (Eq a) = (Inum bs a = 0)" + "Ifm bbs bs (NEq a) = (Inum bs a \ 0)" + "Ifm bbs bs (Dvd i b) = (i dvd Inum bs b)" + "Ifm bbs bs (NDvd i b) = (\(i dvd Inum bs b))" + "Ifm bbs bs (NOT p) = (\ (Ifm bbs bs p))" + "Ifm bbs bs (And p q) = (Ifm bbs bs p \ Ifm bbs bs q)" + "Ifm bbs bs (Or p q) = (Ifm bbs bs p \ Ifm bbs bs q)" + "Ifm bbs bs (Imp p q) = ((Ifm bbs bs p) \ (Ifm bbs bs q))" + "Ifm bbs bs (Iff p q) = (Ifm bbs bs p = Ifm bbs bs q)" + "Ifm bbs bs (E p) = (\ x. Ifm bbs (x#bs) p)" + "Ifm bbs bs (A p) = (\ x. Ifm bbs (x#bs) p)" + "Ifm bbs bs (Closed n) = bbs!n" + "Ifm bbs bs (NClosed n) = (\ bbs!n)" + +consts prep :: "fm \ fm" +recdef prep "measure fmsize" + "prep (E T) = T" + "prep (E F) = F" + "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))" + "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))" + "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" + "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))" + "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" + "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" + "prep (E p) = E (prep p)" + "prep (A (And p q)) = And (prep (A p)) (prep (A q))" + "prep (A p) = prep (NOT (E (NOT p)))" + "prep (NOT (NOT p)) = prep p" + "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))" + "prep (NOT (A p)) = prep (E (NOT p))" + "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))" + "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))" + "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))" + "prep (NOT p) = NOT (prep p)" + "prep (Or p q) = Or (prep p) (prep q)" + "prep (And p q) = And (prep p) (prep q)" + "prep (Imp p q) = prep (Or (NOT p) q)" + "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))" + "prep p = p" +(hints simp add: fmsize_pos) +lemma prep: "Ifm bbs bs (prep p) = Ifm bbs bs p" +by (induct p arbitrary: bs rule: prep.induct, auto) + + + (* Quantifier freeness *) +consts qfree:: "fm \ bool" +recdef qfree "measure size" + "qfree (E p) = False" + "qfree (A p) = False" + "qfree (NOT p) = qfree p" + "qfree (And p q) = (qfree p \ qfree q)" + "qfree (Or p q) = (qfree p \ qfree q)" + "qfree (Imp p q) = (qfree p \ qfree q)" + "qfree (Iff p q) = (qfree p \ qfree q)" + "qfree p = True" + + (* Boundedness and substitution *) +consts + numbound0:: "num \ bool" (* a num is INDEPENDENT of Bound 0 *) + bound0:: "fm \ bool" (* A Formula is independent of Bound 0 *) + subst0:: "num \ fm \ fm" (* substitue a num into a formula for Bound 0 *) +primrec + "numbound0 (C c) = True" + "numbound0 (Bound n) = (n>0)" + "numbound0 (CN n i a) = (n >0 \ numbound0 a)" + "numbound0 (Neg a) = numbound0 a" + "numbound0 (Add a b) = (numbound0 a \ numbound0 b)" + "numbound0 (Sub a b) = (numbound0 a \ numbound0 b)" + "numbound0 (Mul i a) = numbound0 a" + +lemma numbound0_I: + assumes nb: "numbound0 a" + shows "Inum (b#bs) a = Inum (b'#bs) a" +using nb +by (induct a rule: numbound0.induct) (auto simp add: gr0_conv_Suc) + +primrec + "bound0 T = True" + "bound0 F = True" + "bound0 (Lt a) = numbound0 a" + "bound0 (Le a) = numbound0 a" + "bound0 (Gt a) = numbound0 a" + "bound0 (Ge a) = numbound0 a" + "bound0 (Eq a) = numbound0 a" + "bound0 (NEq a) = numbound0 a" + "bound0 (Dvd i a) = numbound0 a" + "bound0 (NDvd i a) = numbound0 a" + "bound0 (NOT p) = bound0 p" + "bound0 (And p q) = (bound0 p \ bound0 q)" + "bound0 (Or p q) = (bound0 p \ bound0 q)" + "bound0 (Imp p q) = ((bound0 p) \ (bound0 q))" + "bound0 (Iff p q) = (bound0 p \ bound0 q)" + "bound0 (E p) = False" + "bound0 (A p) = False" + "bound0 (Closed P) = True" + "bound0 (NClosed P) = True" +lemma bound0_I: + assumes bp: "bound0 p" + shows "Ifm bbs (b#bs) p = Ifm bbs (b'#bs) p" +using bp numbound0_I[where b="b" and bs="bs" and b'="b'"] +by (induct p rule: bound0.induct) (auto simp add: gr0_conv_Suc) + +fun numsubst0:: "num \ num \ num" where + "numsubst0 t (C c) = (C c)" +| "numsubst0 t (Bound n) = (if n=0 then t else Bound n)" +| "numsubst0 t (CN 0 i a) = Add (Mul i t) (numsubst0 t a)" +| "numsubst0 t (CN n i a) = CN n i (numsubst0 t a)" +| "numsubst0 t (Neg a) = Neg (numsubst0 t a)" +| "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)" +| "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)" +| "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)" + +lemma numsubst0_I: + "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t" +by (induct t rule: numsubst0.induct,auto simp:nth_Cons') + +lemma numsubst0_I': + "numbound0 a \ Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t" +by (induct t rule: numsubst0.induct, auto simp: nth_Cons' numbound0_I[where b="b" and b'="b'"]) + +primrec + "subst0 t T = T" + "subst0 t F = F" + "subst0 t (Lt a) = Lt (numsubst0 t a)" + "subst0 t (Le a) = Le (numsubst0 t a)" + "subst0 t (Gt a) = Gt (numsubst0 t a)" + "subst0 t (Ge a) = Ge (numsubst0 t a)" + "subst0 t (Eq a) = Eq (numsubst0 t a)" + "subst0 t (NEq a) = NEq (numsubst0 t a)" + "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)" + "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)" + "subst0 t (NOT p) = NOT (subst0 t p)" + "subst0 t (And p q) = And (subst0 t p) (subst0 t q)" + "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)" + "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)" + "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)" + "subst0 t (Closed P) = (Closed P)" + "subst0 t (NClosed P) = (NClosed P)" + +lemma subst0_I: assumes qfp: "qfree p" + shows "Ifm bbs (b#bs) (subst0 a p) = Ifm bbs ((Inum (b#bs) a)#bs) p" + using qfp numsubst0_I[where b="b" and bs="bs" and a="a"] + by (induct p) (simp_all add: gr0_conv_Suc) + + +consts + decrnum:: "num \ num" + decr :: "fm \ fm" + +recdef decrnum "measure size" + "decrnum (Bound n) = Bound (n - 1)" + "decrnum (Neg a) = Neg (decrnum a)" + "decrnum (Add a b) = Add (decrnum a) (decrnum b)" + "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" + "decrnum (Mul c a) = Mul c (decrnum a)" + "decrnum (CN n i a) = (CN (n - 1) i (decrnum a))" + "decrnum a = a" + +recdef decr "measure size" + "decr (Lt a) = Lt (decrnum a)" + "decr (Le a) = Le (decrnum a)" + "decr (Gt a) = Gt (decrnum a)" + "decr (Ge a) = Ge (decrnum a)" + "decr (Eq a) = Eq (decrnum a)" + "decr (NEq a) = NEq (decrnum a)" + "decr (Dvd i a) = Dvd i (decrnum a)" + "decr (NDvd i a) = NDvd i (decrnum a)" + "decr (NOT p) = NOT (decr p)" + "decr (And p q) = And (decr p) (decr q)" + "decr (Or p q) = Or (decr p) (decr q)" + "decr (Imp p q) = Imp (decr p) (decr q)" + "decr (Iff p q) = Iff (decr p) (decr q)" + "decr p = p" + +lemma decrnum: assumes nb: "numbound0 t" + shows "Inum (x#bs) t = Inum bs (decrnum t)" + using nb by (induct t rule: decrnum.induct, auto simp add: gr0_conv_Suc) + +lemma decr: assumes nb: "bound0 p" + shows "Ifm bbs (x#bs) p = Ifm bbs bs (decr p)" + using nb + by (induct p rule: decr.induct, simp_all add: gr0_conv_Suc decrnum) + +lemma decr_qf: "bound0 p \ qfree (decr p)" +by (induct p, simp_all) + +consts + isatom :: "fm \ bool" (* test for atomicity *) +recdef isatom "measure size" + "isatom T = True" + "isatom F = True" + "isatom (Lt a) = True" + "isatom (Le a) = True" + "isatom (Gt a) = True" + "isatom (Ge a) = True" + "isatom (Eq a) = True" + "isatom (NEq a) = True" + "isatom (Dvd i b) = True" + "isatom (NDvd i b) = True" + "isatom (Closed P) = True" + "isatom (NClosed P) = True" + "isatom p = False" + +lemma numsubst0_numbound0: assumes nb: "numbound0 t" + shows "numbound0 (numsubst0 t a)" +using nb apply (induct a rule: numbound0.induct) +apply simp_all +apply (case_tac n, simp_all) +done + +lemma subst0_bound0: assumes qf: "qfree p" and nb: "numbound0 t" + shows "bound0 (subst0 t p)" +using qf numsubst0_numbound0[OF nb] by (induct p rule: subst0.induct, auto) + +lemma bound0_qf: "bound0 p \ qfree p" +by (induct p, simp_all) + + +constdefs djf:: "('a \ fm) \ 'a \ fm \ fm" + "djf f p q \ (if q=T then T else if q=F then f p else + (let fp = f p in case fp of T \ T | F \ q | _ \ Or (f p) q))" +constdefs evaldjf:: "('a \ fm) \ 'a list \ fm" + "evaldjf f ps \ foldr (djf f) ps F" + +lemma djf_Or: "Ifm bbs bs (djf f p q) = Ifm bbs bs (Or (f p) q)" +by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) +(cases "f p", simp_all add: Let_def djf_def) + +lemma evaldjf_ex: "Ifm bbs bs (evaldjf f ps) = (\ p \ set ps. Ifm bbs bs (f p))" + by(induct ps, simp_all add: evaldjf_def djf_Or) + +lemma evaldjf_bound0: + assumes nb: "\ x\ set xs. bound0 (f x)" + shows "bound0 (evaldjf f xs)" + using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) + +lemma evaldjf_qf: + assumes nb: "\ x\ set xs. qfree (f x)" + shows "qfree (evaldjf f xs)" + using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) + +consts disjuncts :: "fm \ fm list" +recdef disjuncts "measure size" + "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)" + "disjuncts F = []" + "disjuncts p = [p]" + +lemma disjuncts: "(\ q\ set (disjuncts p). Ifm bbs bs q) = Ifm bbs bs p" +by(induct p rule: disjuncts.induct, auto) + +lemma disjuncts_nb: "bound0 p \ \ q\ set (disjuncts p). bound0 q" +proof- + assume nb: "bound0 p" + hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto) + thus ?thesis by (simp only: list_all_iff) +qed + +lemma disjuncts_qf: "qfree p \ \ q\ set (disjuncts p). qfree q" +proof- + assume qf: "qfree p" + hence "list_all qfree (disjuncts p)" + by (induct p rule: disjuncts.induct, auto) + thus ?thesis by (simp only: list_all_iff) +qed + +constdefs DJ :: "(fm \ fm) \ fm \ fm" + "DJ f p \ evaldjf f (disjuncts p)" + +lemma DJ: assumes fdj: "\ p q. f (Or p q) = Or (f p) (f q)" + and fF: "f F = F" + shows "Ifm bbs bs (DJ f p) = Ifm bbs bs (f p)" +proof- + have "Ifm bbs bs (DJ f p) = (\ q \ set (disjuncts p). Ifm bbs bs (f q))" + by (simp add: DJ_def evaldjf_ex) + also have "\ = Ifm bbs bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto) + finally show ?thesis . +qed + +lemma DJ_qf: assumes + fqf: "\ p. qfree p \ qfree (f p)" + shows "\p. qfree p \ qfree (DJ f p) " +proof(clarify) + fix p assume qf: "qfree p" + have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def) + from disjuncts_qf[OF qf] have "\ q\ set (disjuncts p). qfree q" . + with fqf have th':"\ q\ set (disjuncts p). qfree (f q)" by blast + + from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp +qed + +lemma DJ_qe: assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bbs bs (qe p) = Ifm bbs bs (E p))" + shows "\ bs p. qfree p \ qfree (DJ qe p) \ (Ifm bbs bs ((DJ qe p)) = Ifm bbs bs (E p))" +proof(clarify) + fix p::fm and bs + assume qf: "qfree p" + from qe have qth: "\ p. qfree p \ qfree (qe p)" by blast + from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto + have "Ifm bbs bs (DJ qe p) = (\ q\ set (disjuncts p). Ifm bbs bs (qe q))" + by (simp add: DJ_def evaldjf_ex) + also have "\ = (\ q \ set(disjuncts p). Ifm bbs bs (E q))" using qe disjuncts_qf[OF qf] by auto + also have "\ = Ifm bbs bs (E p)" by (induct p rule: disjuncts.induct, auto) + finally show "qfree (DJ qe p) \ Ifm bbs bs (DJ qe p) = Ifm bbs bs (E p)" using qfth by blast +qed + (* Simplification *) + + (* Algebraic simplifications for nums *) +consts bnds:: "num \ nat list" + lex_ns:: "nat list \ nat list \ bool" +recdef bnds "measure size" + "bnds (Bound n) = [n]" + "bnds (CN n c a) = n#(bnds a)" + "bnds (Neg a) = bnds a" + "bnds (Add a b) = (bnds a)@(bnds b)" + "bnds (Sub a b) = (bnds a)@(bnds b)" + "bnds (Mul i a) = bnds a" + "bnds a = []" +recdef lex_ns "measure (\ (xs,ys). length xs + length ys)" + "lex_ns ([], ms) = True" + "lex_ns (ns, []) = False" + "lex_ns (n#ns, m#ms) = (n ((n = m) \ lex_ns (ns,ms))) " +constdefs lex_bnd :: "num \ num \ bool" + "lex_bnd t s \ lex_ns (bnds t, bnds s)" + +consts + numadd:: "num \ num \ num" +recdef numadd "measure (\ (t,s). num_size t + num_size s)" + "numadd (CN n1 c1 r1 ,CN n2 c2 r2) = + (if n1=n2 then + (let c = c1 + c2 + in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2)))) + else if n1 \ n2 then CN n1 c1 (numadd (r1,Add (Mul c2 (Bound n2)) r2)) + else CN n2 c2 (numadd (Add (Mul c1 (Bound n1)) r1,r2)))" + "numadd (CN n1 c1 r1, t) = CN n1 c1 (numadd (r1, t))" + "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" + "numadd (C b1, C b2) = C (b1+b2)" + "numadd (a,b) = Add a b" + +(*function (sequential) + numadd :: "num \ num \ num" +where + "numadd (Add (Mul c1 (Bound n1)) r1) (Add (Mul c2 (Bound n2)) r2) = + (if n1 = n2 then (let c = c1 + c2 + in (if c = 0 then numadd r1 r2 else + Add (Mul c (Bound n1)) (numadd r1 r2))) + else if n1 \ n2 then + Add (Mul c1 (Bound n1)) (numadd r1 (Add (Mul c2 (Bound n2)) r2)) + else + Add (Mul c2 (Bound n2)) (numadd (Add (Mul c1 (Bound n1)) r1) r2))" + | "numadd (Add (Mul c1 (Bound n1)) r1) t = + Add (Mul c1 (Bound n1)) (numadd r1 t)" + | "numadd t (Add (Mul c2 (Bound n2)) r2) = + Add (Mul c2 (Bound n2)) (numadd t r2)" + | "numadd (C b1) (C b2) = C (b1 + b2)" + | "numadd a b = Add a b" +apply pat_completeness apply auto*) + +lemma numadd: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" +apply (induct t s rule: numadd.induct, simp_all add: Let_def) +apply (case_tac "c1+c2 = 0",case_tac "n1 \ n2", simp_all) + apply (case_tac "n1 = n2") + apply(simp_all add: algebra_simps) +apply(simp add: left_distrib[symmetric]) +done + +lemma numadd_nb: "\ numbound0 t ; numbound0 s\ \ numbound0 (numadd (t,s))" +by (induct t s rule: numadd.induct, auto simp add: Let_def) + +fun + nummul :: "int \ num \ num" +where + "nummul i (C j) = C (i * j)" + | "nummul i (CN n c t) = CN n (c*i) (nummul i t)" + | "nummul i t = Mul i t" + +lemma nummul: "\ i. Inum bs (nummul i t) = Inum bs (Mul i t)" +by (induct t rule: nummul.induct, auto simp add: algebra_simps numadd) + +lemma nummul_nb: "\ i. numbound0 t \ numbound0 (nummul i t)" +by (induct t rule: nummul.induct, auto simp add: numadd_nb) + +constdefs numneg :: "num \ num" + "numneg t \ nummul (- 1) t" + +constdefs numsub :: "num \ num \ num" + "numsub s t \ (if s = t then C 0 else numadd (s, numneg t))" + +lemma numneg: "Inum bs (numneg t) = Inum bs (Neg t)" +using numneg_def nummul by simp + +lemma numneg_nb: "numbound0 t \ numbound0 (numneg t)" +using numneg_def nummul_nb by simp + +lemma numsub: "Inum bs (numsub a b) = Inum bs (Sub a b)" +using numneg numadd numsub_def by simp + +lemma numsub_nb: "\ numbound0 t ; numbound0 s\ \ numbound0 (numsub t s)" +using numsub_def numadd_nb numneg_nb by simp + +fun + simpnum :: "num \ num" +where + "simpnum (C j) = C j" + | "simpnum (Bound n) = CN n 1 (C 0)" + | "simpnum (Neg t) = numneg (simpnum t)" + | "simpnum (Add t s) = numadd (simpnum t, simpnum s)" + | "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" + | "simpnum (Mul i t) = (if i = 0 then C 0 else nummul i (simpnum t))" + | "simpnum t = t" + +lemma simpnum_ci: "Inum bs (simpnum t) = Inum bs t" +by (induct t rule: simpnum.induct, auto simp add: numneg numadd numsub nummul) + +lemma simpnum_numbound0: + "numbound0 t \ numbound0 (simpnum t)" +by (induct t rule: simpnum.induct, auto simp add: numadd_nb numsub_nb nummul_nb numneg_nb) + +fun + not :: "fm \ fm" +where + "not (NOT p) = p" + | "not T = F" + | "not F = T" + | "not p = NOT p" +lemma not: "Ifm bbs bs (not p) = Ifm bbs bs (NOT p)" +by (cases p) auto +lemma not_qf: "qfree p \ qfree (not p)" +by (cases p, auto) +lemma not_bn: "bound0 p \ bound0 (not p)" +by (cases p, auto) + +constdefs conj :: "fm \ fm \ fm" + "conj p q \ (if (p = F \ q=F) then F else if p=T then q else if q=T then p else And p q)" +lemma conj: "Ifm bbs bs (conj p q) = Ifm bbs bs (And p q)" +by (cases "p=F \ q=F",simp_all add: conj_def) (cases p,simp_all) + +lemma conj_qf: "\qfree p ; qfree q\ \ qfree (conj p q)" +using conj_def by auto +lemma conj_nb: "\bound0 p ; bound0 q\ \ bound0 (conj p q)" +using conj_def by auto + +constdefs disj :: "fm \ fm \ fm" + "disj p q \ (if (p = T \ q=T) then T else if p=F then q else if q=F then p else Or p q)" + +lemma disj: "Ifm bbs bs (disj p q) = Ifm bbs bs (Or p q)" +by (cases "p=T \ q=T",simp_all add: disj_def) (cases p,simp_all) +lemma disj_qf: "\qfree p ; qfree q\ \ qfree (disj p q)" +using disj_def by auto +lemma disj_nb: "\bound0 p ; bound0 q\ \ bound0 (disj p q)" +using disj_def by auto + +constdefs imp :: "fm \ fm \ fm" + "imp p q \ (if (p = F \ q=T) then T else if p=T then q else if q=F then not p else Imp p q)" +lemma imp: "Ifm bbs bs (imp p q) = Ifm bbs bs (Imp p q)" +by (cases "p=F \ q=T",simp_all add: imp_def,cases p) (simp_all add: not) +lemma imp_qf: "\qfree p ; qfree q\ \ qfree (imp p q)" +using imp_def by (cases "p=F \ q=T",simp_all add: imp_def,cases p) (simp_all add: not_qf) +lemma imp_nb: "\bound0 p ; bound0 q\ \ bound0 (imp p q)" +using imp_def by (cases "p=F \ q=T",simp_all add: imp_def,cases p) simp_all + +constdefs iff :: "fm \ fm \ fm" + "iff p q \ (if (p = q) then T else if (p = not q \ not p = q) then F else + if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else + Iff p q)" +lemma iff: "Ifm bbs bs (iff p q) = Ifm bbs bs (Iff p q)" + by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp add:not) +(cases "not p= q", auto simp add:not) +lemma iff_qf: "\qfree p ; qfree q\ \ qfree (iff p q)" + by (unfold iff_def,cases "p=q", auto simp add: not_qf) +lemma iff_nb: "\bound0 p ; bound0 q\ \ bound0 (iff p q)" +using iff_def by (unfold iff_def,cases "p=q", auto simp add: not_bn) + +function (sequential) + simpfm :: "fm \ fm" +where + "simpfm (And p q) = conj (simpfm p) (simpfm q)" + | "simpfm (Or p q) = disj (simpfm p) (simpfm q)" + | "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" + | "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" + | "simpfm (NOT p) = not (simpfm p)" + | "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \ if (v < 0) then T else F + | _ \ Lt a')" + | "simpfm (Le a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Le a')" + | "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \ if (v > 0) then T else F | _ \ Gt a')" + | "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Ge a')" + | "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \ if (v = 0) then T else F | _ \ Eq a')" + | "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ NEq a')" + | "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a) + else if (abs i = 1) then T + else let a' = simpnum a in case a' of C v \ if (i dvd v) then T else F | _ \ Dvd i a')" + | "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a) + else if (abs i = 1) then F + else let a' = simpnum a in case a' of C v \ if (\(i dvd v)) then T else F | _ \ NDvd i a')" + | "simpfm p = p" +by pat_completeness auto +termination by (relation "measure fmsize") auto + +lemma simpfm: "Ifm bbs bs (simpfm p) = Ifm bbs bs p" +proof(induct p rule: simpfm.induct) + case (6 a) let ?sa = "simpnum a" from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa + by (cases ?sa, simp_all add: Let_def)} + ultimately show ?case by blast +next + case (7 a) let ?sa = "simpnum a" + from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa + by (cases ?sa, simp_all add: Let_def)} + ultimately show ?case by blast +next + case (8 a) let ?sa = "simpnum a" + from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa + by (cases ?sa, simp_all add: Let_def)} + ultimately show ?case by blast +next + case (9 a) let ?sa = "simpnum a" + from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa + by (cases ?sa, simp_all add: Let_def)} + ultimately show ?case by blast +next + case (10 a) let ?sa = "simpnum a" + from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa + by (cases ?sa, simp_all add: Let_def)} + ultimately show ?case by blast +next + case (11 a) let ?sa = "simpnum a" + from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa + by (cases ?sa, simp_all add: Let_def)} + ultimately show ?case by blast +next + case (12 i a) let ?sa = "simpnum a" from simpnum_ci + have sa: "Inum bs ?sa = Inum bs a" by simp + have "i=0 \ abs i = 1 \ (i\0 \ (abs i \ 1))" by auto + {assume "i=0" hence ?case using "12.hyps" by (simp add: dvd_def Let_def)} + moreover + {assume i1: "abs i = 1" + from zdvd_1_left[where m = "Inum bs a"] uminus_dvd_conv[where d="1" and t="Inum bs a"] + have ?case using i1 apply (cases "i=0", simp_all add: Let_def) + by (cases "i > 0", simp_all)} + moreover + {assume inz: "i\0" and cond: "abs i \ 1" + {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond + by (cases "abs i = 1", auto) } + moreover {assume "\ (\ v. ?sa = C v)" + hence "simpfm (Dvd i a) = Dvd i ?sa" using inz cond + by (cases ?sa, auto simp add: Let_def) + hence ?case using sa by simp} + ultimately have ?case by blast} + ultimately show ?case by blast +next + case (13 i a) let ?sa = "simpnum a" from simpnum_ci + have sa: "Inum bs ?sa = Inum bs a" by simp + have "i=0 \ abs i = 1 \ (i\0 \ (abs i \ 1))" by auto + {assume "i=0" hence ?case using "13.hyps" by (simp add: dvd_def Let_def)} + moreover + {assume i1: "abs i = 1" + from zdvd_1_left[where m = "Inum bs a"] uminus_dvd_conv[where d="1" and t="Inum bs a"] + have ?case using i1 apply (cases "i=0", simp_all add: Let_def) + apply (cases "i > 0", simp_all) done} + moreover + {assume inz: "i\0" and cond: "abs i \ 1" + {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond + by (cases "abs i = 1", auto) } + moreover {assume "\ (\ v. ?sa = C v)" + hence "simpfm (NDvd i a) = NDvd i ?sa" using inz cond + by (cases ?sa, auto simp add: Let_def) + hence ?case using sa by simp} + ultimately have ?case by blast} + ultimately show ?case by blast +qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not) + +lemma simpfm_bound0: "bound0 p \ bound0 (simpfm p)" +proof(induct p rule: simpfm.induct) + case (6 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (7 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (8 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (9 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (10 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (11 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (12 i a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +next + case (13 i a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def) +qed(auto simp add: disj_def imp_def iff_def conj_def not_bn) + +lemma simpfm_qf: "qfree p \ qfree (simpfm p)" +by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def) + (case_tac "simpnum a",auto)+ + + (* Generic quantifier elimination *) +consts qelim :: "fm \ (fm \ fm) \ fm" +recdef qelim "measure fmsize" + "qelim (E p) = (\ qe. DJ qe (qelim p qe))" + "qelim (A p) = (\ qe. not (qe ((qelim (NOT p) qe))))" + "qelim (NOT p) = (\ qe. not (qelim p qe))" + "qelim (And p q) = (\ qe. conj (qelim p qe) (qelim q qe))" + "qelim (Or p q) = (\ qe. disj (qelim p qe) (qelim q qe))" + "qelim (Imp p q) = (\ qe. imp (qelim p qe) (qelim q qe))" + "qelim (Iff p q) = (\ qe. iff (qelim p qe) (qelim q qe))" + "qelim p = (\ y. simpfm p)" + +(*function (sequential) + qelim :: "(fm \ fm) \ fm \ fm" +where + "qelim qe (E p) = DJ qe (qelim qe p)" + | "qelim qe (A p) = not (qe ((qelim qe (NOT p))))" + | "qelim qe (NOT p) = not (qelim qe p)" + | "qelim qe (And p q) = conj (qelim qe p) (qelim qe q)" + | "qelim qe (Or p q) = disj (qelim qe p) (qelim qe q)" + | "qelim qe (Imp p q) = imp (qelim qe p) (qelim qe q)" + | "qelim qe (Iff p q) = iff (qelim qe p) (qelim qe q)" + | "qelim qe p = simpfm p" +by pat_completeness auto +termination by (relation "measure (fmsize o snd)") auto*) + +lemma qelim_ci: + assumes qe_inv: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bbs bs (qe p) = Ifm bbs bs (E p))" + shows "\ bs. qfree (qelim p qe) \ (Ifm bbs bs (qelim p qe) = Ifm bbs bs p)" +using qe_inv DJ_qe[OF qe_inv] +by(induct p rule: qelim.induct) +(auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf + simpfm simpfm_qf simp del: simpfm.simps) + (* Linearity for fm where Bound 0 ranges over \ *) + +fun + zsplit0 :: "num \ int \ num" (* splits the bounded from the unbounded part*) +where + "zsplit0 (C c) = (0,C c)" + | "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))" + | "zsplit0 (CN n i a) = + (let (i',a') = zsplit0 a + in if n=0 then (i+i', a') else (i',CN n i a'))" + | "zsplit0 (Neg a) = (let (i',a') = zsplit0 a in (-i', Neg a'))" + | "zsplit0 (Add a b) = (let (ia,a') = zsplit0 a ; + (ib,b') = zsplit0 b + in (ia+ib, Add a' b'))" + | "zsplit0 (Sub a b) = (let (ia,a') = zsplit0 a ; + (ib,b') = zsplit0 b + in (ia-ib, Sub a' b'))" + | "zsplit0 (Mul i a) = (let (i',a') = zsplit0 a in (i*i', Mul i a'))" + +lemma zsplit0_I: + shows "\ n a. zsplit0 t = (n,a) \ (Inum ((x::int) #bs) (CN 0 n a) = Inum (x #bs) t) \ numbound0 a" + (is "\ n a. ?S t = (n,a) \ (?I x (CN 0 n a) = ?I x t) \ ?N a") +proof(induct t rule: zsplit0.induct) + case (1 c n a) thus ?case by auto +next + case (2 m n a) thus ?case by (cases "m=0") auto +next + case (3 m i a n a') + let ?j = "fst (zsplit0 a)" + let ?b = "snd (zsplit0 a)" + have abj: "zsplit0 a = (?j,?b)" by simp + {assume "m\0" + with prems(1)[OF abj] prems(2) have ?case by (auto simp add: Let_def split_def)} + moreover + {assume m0: "m =0" + from abj have th: "a'=?b \ n=i+?j" using prems + by (simp add: Let_def split_def) + from abj prems have th2: "(?I x (CN 0 ?j ?b) = ?I x a) \ ?N ?b" by blast + from th have "?I x (CN 0 n a') = ?I x (CN 0 (i+?j) ?b)" by simp + also from th2 have "\ = ?I x (CN 0 i (CN 0 ?j ?b))" by (simp add: left_distrib) + finally have "?I x (CN 0 n a') = ?I x (CN 0 i a)" using th2 by simp + with th2 th have ?case using m0 by blast} +ultimately show ?case by blast +next + case (4 t n a) + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \ n=-?nt" using prems + by (simp add: Let_def split_def) + from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + from th2[simplified] th[simplified] show ?case by simp +next + case (5 s t n a) + let ?ns = "fst (zsplit0 s)" + let ?as = "snd (zsplit0 s)" + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abjs: "zsplit0 s = (?ns,?as)" by simp + moreover have abjt: "zsplit0 t = (?nt,?at)" by simp + ultimately have th: "a=Add ?as ?at \ n=?ns + ?nt" using prems + by (simp add: Let_def split_def) + from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast + from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \ numbound0 xb)" by auto + with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast + from th3[simplified] th2[simplified] th[simplified] show ?case + by (simp add: left_distrib) +next + case (6 s t n a) + let ?ns = "fst (zsplit0 s)" + let ?as = "snd (zsplit0 s)" + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abjs: "zsplit0 s = (?ns,?as)" by simp + moreover have abjt: "zsplit0 t = (?nt,?at)" by simp + ultimately have th: "a=Sub ?as ?at \ n=?ns - ?nt" using prems + by (simp add: Let_def split_def) + from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast + from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \ numbound0 xb)" by auto + with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast + from th3[simplified] th2[simplified] th[simplified] show ?case + by (simp add: left_diff_distrib) +next + case (7 i t n a) + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \ n=i*?nt" using prems + by (simp add: Let_def split_def) + from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + hence " ?I x (Mul i t) = i * ?I x (CN 0 ?nt ?at)" by simp + also have "\ = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: right_distrib) + finally show ?case using th th2 by simp +qed + +consts + iszlfm :: "fm \ bool" (* Linearity test for fm *) +recdef iszlfm "measure size" + "iszlfm (And p q) = (iszlfm p \ iszlfm q)" + "iszlfm (Or p q) = (iszlfm p \ iszlfm q)" + "iszlfm (Eq (CN 0 c e)) = (c>0 \ numbound0 e)" + "iszlfm (NEq (CN 0 c e)) = (c>0 \ numbound0 e)" + "iszlfm (Lt (CN 0 c e)) = (c>0 \ numbound0 e)" + "iszlfm (Le (CN 0 c e)) = (c>0 \ numbound0 e)" + "iszlfm (Gt (CN 0 c e)) = (c>0 \ numbound0 e)" + "iszlfm (Ge (CN 0 c e)) = ( c>0 \ numbound0 e)" + "iszlfm (Dvd i (CN 0 c e)) = + (c>0 \ i>0 \ numbound0 e)" + "iszlfm (NDvd i (CN 0 c e))= + (c>0 \ i>0 \ numbound0 e)" + "iszlfm p = (isatom p \ (bound0 p))" + +lemma zlin_qfree: "iszlfm p \ qfree p" + by (induct p rule: iszlfm.induct) auto + +consts + zlfm :: "fm \ fm" (* Linearity transformation for fm *) +recdef zlfm "measure fmsize" + "zlfm (And p q) = And (zlfm p) (zlfm q)" + "zlfm (Or p q) = Or (zlfm p) (zlfm q)" + "zlfm (Imp p q) = Or (zlfm (NOT p)) (zlfm q)" + "zlfm (Iff p q) = Or (And (zlfm p) (zlfm q)) (And (zlfm (NOT p)) (zlfm (NOT q)))" + "zlfm (Lt a) = (let (c,r) = zsplit0 a in + if c=0 then Lt r else + if c>0 then (Lt (CN 0 c r)) else (Gt (CN 0 (- c) (Neg r))))" + "zlfm (Le a) = (let (c,r) = zsplit0 a in + if c=0 then Le r else + if c>0 then (Le (CN 0 c r)) else (Ge (CN 0 (- c) (Neg r))))" + "zlfm (Gt a) = (let (c,r) = zsplit0 a in + if c=0 then Gt r else + if c>0 then (Gt (CN 0 c r)) else (Lt (CN 0 (- c) (Neg r))))" + "zlfm (Ge a) = (let (c,r) = zsplit0 a in + if c=0 then Ge r else + if c>0 then (Ge (CN 0 c r)) else (Le (CN 0 (- c) (Neg r))))" + "zlfm (Eq a) = (let (c,r) = zsplit0 a in + if c=0 then Eq r else + if c>0 then (Eq (CN 0 c r)) else (Eq (CN 0 (- c) (Neg r))))" + "zlfm (NEq a) = (let (c,r) = zsplit0 a in + if c=0 then NEq r else + if c>0 then (NEq (CN 0 c r)) else (NEq (CN 0 (- c) (Neg r))))" + "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a) + else (let (c,r) = zsplit0 a in + if c=0 then (Dvd (abs i) r) else + if c>0 then (Dvd (abs i) (CN 0 c r)) + else (Dvd (abs i) (CN 0 (- c) (Neg r)))))" + "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a) + else (let (c,r) = zsplit0 a in + if c=0 then (NDvd (abs i) r) else + if c>0 then (NDvd (abs i) (CN 0 c r)) + else (NDvd (abs i) (CN 0 (- c) (Neg r)))))" + "zlfm (NOT (And p q)) = Or (zlfm (NOT p)) (zlfm (NOT q))" + "zlfm (NOT (Or p q)) = And (zlfm (NOT p)) (zlfm (NOT q))" + "zlfm (NOT (Imp p q)) = And (zlfm p) (zlfm (NOT q))" + "zlfm (NOT (Iff p q)) = Or (And(zlfm p) (zlfm(NOT q))) (And (zlfm(NOT p)) (zlfm q))" + "zlfm (NOT (NOT p)) = zlfm p" + "zlfm (NOT T) = F" + "zlfm (NOT F) = T" + "zlfm (NOT (Lt a)) = zlfm (Ge a)" + "zlfm (NOT (Le a)) = zlfm (Gt a)" + "zlfm (NOT (Gt a)) = zlfm (Le a)" + "zlfm (NOT (Ge a)) = zlfm (Lt a)" + "zlfm (NOT (Eq a)) = zlfm (NEq a)" + "zlfm (NOT (NEq a)) = zlfm (Eq a)" + "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)" + "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)" + "zlfm (NOT (Closed P)) = NClosed P" + "zlfm (NOT (NClosed P)) = Closed P" + "zlfm p = p" (hints simp add: fmsize_pos) + +lemma zlfm_I: + assumes qfp: "qfree p" + shows "(Ifm bbs (i#bs) (zlfm p) = Ifm bbs (i# bs) p) \ iszlfm (zlfm p)" + (is "(?I (?l p) = ?I p) \ ?L (?l p)") +using qfp +proof(induct p rule: zlfm.induct) + case (5 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + from prems Ia nb show ?case + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done +next + case (6 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + from prems Ia nb show ?case + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done +next + case (7 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + from prems Ia nb show ?case + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done +next + case (8 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + from prems Ia nb show ?case + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done +next + case (9 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + from prems Ia nb show ?case + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done +next + case (10 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + from prems Ia nb show ?case + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done +next + case (11 j a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0) \ (j\ 0 \ ?c<0)" by arith + moreover + {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def) + hence ?case using prems by (simp del: zlfm.simps add: zdvd_0_left)} + moreover + {assume "?c=0" and "j\0" hence ?case + using zsplit0_I[OF spl, where x="i" and bs="bs"] + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done} + moreover + {assume cp: "?c > 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" + by (simp add: nb Let_def split_def) + hence ?case using Ia cp jnz by (simp add: Let_def split_def)} + moreover + {assume cn: "?c < 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" + by (simp add: nb Let_def split_def) + hence ?case using Ia cn jnz zdvd_zminus_iff[where m="abs j" and n="?c*i + ?N ?r" ] + by (simp add: Let_def split_def) } + ultimately show ?case by blast +next + case (12 j a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (i#bs) t" + have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0) \ (j\ 0 \ ?c<0)" by arith + moreover + {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def) + hence ?case using prems by (simp del: zlfm.simps add: zdvd_0_left)} + moreover + {assume "?c=0" and "j\0" hence ?case + using zsplit0_I[OF spl, where x="i" and bs="bs"] + apply (auto simp add: Let_def split_def algebra_simps) + apply (cases "?r",auto) + apply (case_tac nat, auto) + done} + moreover + {assume cp: "?c > 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" + by (simp add: nb Let_def split_def) + hence ?case using Ia cp jnz by (simp add: Let_def split_def) } + moreover + {assume cn: "?c < 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" + by (simp add: nb Let_def split_def) + hence ?case using Ia cn jnz zdvd_zminus_iff[where m="abs j" and n="?c*i + ?N ?r" ] + by (simp add: Let_def split_def)} + ultimately show ?case by blast +qed auto + +consts + plusinf:: "fm \ fm" (* Virtual substitution of +\*) + minusinf:: "fm \ fm" (* Virtual substitution of -\*) + \ :: "fm \ int" (* Compute lcm {d| N\<^isup>?\<^isup> Dvd c*x+t \ p}*) + d\ :: "fm \ int \ bool" (* checks if a given l divides all the ds above*) + +recdef minusinf "measure size" + "minusinf (And p q) = And (minusinf p) (minusinf q)" + "minusinf (Or p q) = Or (minusinf p) (minusinf q)" + "minusinf (Eq (CN 0 c e)) = F" + "minusinf (NEq (CN 0 c e)) = T" + "minusinf (Lt (CN 0 c e)) = T" + "minusinf (Le (CN 0 c e)) = T" + "minusinf (Gt (CN 0 c e)) = F" + "minusinf (Ge (CN 0 c e)) = F" + "minusinf p = p" + +lemma minusinf_qfree: "qfree p \ qfree (minusinf p)" + by (induct p rule: minusinf.induct, auto) + +recdef plusinf "measure size" + "plusinf (And p q) = And (plusinf p) (plusinf q)" + "plusinf (Or p q) = Or (plusinf p) (plusinf q)" + "plusinf (Eq (CN 0 c e)) = F" + "plusinf (NEq (CN 0 c e)) = T" + "plusinf (Lt (CN 0 c e)) = F" + "plusinf (Le (CN 0 c e)) = F" + "plusinf (Gt (CN 0 c e)) = T" + "plusinf (Ge (CN 0 c e)) = T" + "plusinf p = p" + +recdef \ "measure size" + "\ (And p q) = zlcm (\ p) (\ q)" + "\ (Or p q) = zlcm (\ p) (\ q)" + "\ (Dvd i (CN 0 c e)) = i" + "\ (NDvd i (CN 0 c e)) = i" + "\ p = 1" + +recdef d\ "measure size" + "d\ (And p q) = (\ d. d\ p d \ d\ q d)" + "d\ (Or p q) = (\ d. d\ p d \ d\ q d)" + "d\ (Dvd i (CN 0 c e)) = (\ d. i dvd d)" + "d\ (NDvd i (CN 0 c e)) = (\ d. i dvd d)" + "d\ p = (\ d. True)" + +lemma delta_mono: + assumes lin: "iszlfm p" + and d: "d dvd d'" + and ad: "d\ p d" + shows "d\ p d'" + using lin ad d +proof(induct p rule: iszlfm.induct) + case (9 i c e) thus ?case using d + by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) +next + case (10 i c e) thus ?case using d + by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) +qed simp_all + +lemma \ : assumes lin:"iszlfm p" + shows "d\ p (\ p) \ \ p >0" +using lin +proof (induct p rule: iszlfm.induct) + case (1 p q) + let ?d = "\ (And p q)" + from prems zlcm_pos have dp: "?d >0" by simp + have d1: "\ p dvd \ (And p q)" using prems by simp + hence th: "d\ p ?d" using delta_mono prems(3-4) by(simp del:dvd_zlcm_self1) + have "\ q dvd \ (And p q)" using prems by simp + hence th': "d\ q ?d" using delta_mono prems by(simp del:dvd_zlcm_self2) + from th th' dp show ?case by simp +next + case (2 p q) + let ?d = "\ (And p q)" + from prems zlcm_pos have dp: "?d >0" by simp + have "\ p dvd \ (And p q)" using prems by simp + hence th: "d\ p ?d" using delta_mono prems by(simp del:dvd_zlcm_self1) + have "\ q dvd \ (And p q)" using prems by simp + hence th': "d\ q ?d" using delta_mono prems by(simp del:dvd_zlcm_self2) + from th th' dp show ?case by simp +qed simp_all + + +consts + a\ :: "fm \ int \ fm" (* adjusts the coeffitients of a formula *) + d\ :: "fm \ int \ bool" (* tests if all coeffs c of c divide a given l*) + \ :: "fm \ int" (* computes the lcm of all coefficients of x*) + \ :: "fm \ num list" + \ :: "fm \ num list" + +recdef a\ "measure size" + "a\ (And p q) = (\ k. And (a\ p k) (a\ q k))" + "a\ (Or p q) = (\ k. Or (a\ p k) (a\ q k))" + "a\ (Eq (CN 0 c e)) = (\ k. Eq (CN 0 1 (Mul (k div c) e)))" + "a\ (NEq (CN 0 c e)) = (\ k. NEq (CN 0 1 (Mul (k div c) e)))" + "a\ (Lt (CN 0 c e)) = (\ k. Lt (CN 0 1 (Mul (k div c) e)))" + "a\ (Le (CN 0 c e)) = (\ k. Le (CN 0 1 (Mul (k div c) e)))" + "a\ (Gt (CN 0 c e)) = (\ k. Gt (CN 0 1 (Mul (k div c) e)))" + "a\ (Ge (CN 0 c e)) = (\ k. Ge (CN 0 1 (Mul (k div c) e)))" + "a\ (Dvd i (CN 0 c e)) =(\ k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" + "a\ (NDvd i (CN 0 c e))=(\ k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" + "a\ p = (\ k. p)" + +recdef d\ "measure size" + "d\ (And p q) = (\ k. (d\ p k) \ (d\ q k))" + "d\ (Or p q) = (\ k. (d\ p k) \ (d\ q k))" + "d\ (Eq (CN 0 c e)) = (\ k. c dvd k)" + "d\ (NEq (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Lt (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Le (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Gt (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Ge (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Dvd i (CN 0 c e)) =(\ k. c dvd k)" + "d\ (NDvd i (CN 0 c e))=(\ k. c dvd k)" + "d\ p = (\ k. True)" + +recdef \ "measure size" + "\ (And p q) = zlcm (\ p) (\ q)" + "\ (Or p q) = zlcm (\ p) (\ q)" + "\ (Eq (CN 0 c e)) = c" + "\ (NEq (CN 0 c e)) = c" + "\ (Lt (CN 0 c e)) = c" + "\ (Le (CN 0 c e)) = c" + "\ (Gt (CN 0 c e)) = c" + "\ (Ge (CN 0 c e)) = c" + "\ (Dvd i (CN 0 c e)) = c" + "\ (NDvd i (CN 0 c e))= c" + "\ p = 1" + +recdef \ "measure size" + "\ (And p q) = (\ p @ \ q)" + "\ (Or p q) = (\ p @ \ q)" + "\ (Eq (CN 0 c e)) = [Sub (C -1) e]" + "\ (NEq (CN 0 c e)) = [Neg e]" + "\ (Lt (CN 0 c e)) = []" + "\ (Le (CN 0 c e)) = []" + "\ (Gt (CN 0 c e)) = [Neg e]" + "\ (Ge (CN 0 c e)) = [Sub (C -1) e]" + "\ p = []" + +recdef \ "measure size" + "\ (And p q) = (\ p @ \ q)" + "\ (Or p q) = (\ p @ \ q)" + "\ (Eq (CN 0 c e)) = [Add (C -1) e]" + "\ (NEq (CN 0 c e)) = [e]" + "\ (Lt (CN 0 c e)) = [e]" + "\ (Le (CN 0 c e)) = [Add (C -1) e]" + "\ (Gt (CN 0 c e)) = []" + "\ (Ge (CN 0 c e)) = []" + "\ p = []" +consts mirror :: "fm \ fm" +recdef mirror "measure size" + "mirror (And p q) = And (mirror p) (mirror q)" + "mirror (Or p q) = Or (mirror p) (mirror q)" + "mirror (Eq (CN 0 c e)) = Eq (CN 0 c (Neg e))" + "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))" + "mirror (Lt (CN 0 c e)) = Gt (CN 0 c (Neg e))" + "mirror (Le (CN 0 c e)) = Ge (CN 0 c (Neg e))" + "mirror (Gt (CN 0 c e)) = Lt (CN 0 c (Neg e))" + "mirror (Ge (CN 0 c e)) = Le (CN 0 c (Neg e))" + "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))" + "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))" + "mirror p = p" + (* Lemmas for the correctness of \\ *) +lemma dvd1_eq1: "x >0 \ (x::int) dvd 1 = (x = 1)" +by simp + +lemma minusinf_inf: + assumes linp: "iszlfm p" + and u: "d\ p 1" + shows "\ (z::int). \ x < z. Ifm bbs (x#bs) (minusinf p) = Ifm bbs (x#bs) p" + (is "?P p" is "\ (z::int). \ x < z. ?I x (?M p) = ?I x p") +using linp u +proof (induct p rule: minusinf.induct) + case (1 p q) thus ?case + by auto (rule_tac x="min z za" in exI,simp) +next + case (2 p q) thus ?case + by auto (rule_tac x="min z za" in exI,simp) +next + case (3 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ + fix a + from 3 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \ 0" + proof(clarsimp) + fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0" + with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] + show "False" by simp + qed + thus ?case by auto +next + case (4 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ + fix a + from 4 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \ 0" + proof(clarsimp) + fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0" + with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] + show "False" by simp + qed + thus ?case by auto +next + case (5 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ + fix a + from 5 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e < 0" + proof(clarsimp) + fix x assume "x < (- Inum (a#bs) e)" + with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] + show "x + Inum (x#bs) e < 0" by simp + qed + thus ?case by auto +next + case (6 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ + fix a + from 6 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \ 0" + proof(clarsimp) + fix x assume "x < (- Inum (a#bs) e)" + with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] + show "x + Inum (x#bs) e \ 0" by simp + qed + thus ?case by auto +next + case (7 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ + fix a + from 7 have "\ x<(- Inum (a#bs) e). \ (c*x + Inum (x#bs) e > 0)" + proof(clarsimp) + fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e > 0" + with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] + show "False" by simp + qed + thus ?case by auto +next + case (8 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ + fix a + from 8 have "\ x<(- Inum (a#bs) e). \ (c*x + Inum (x#bs) e \ 0)" + proof(clarsimp) + fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e \ 0" + with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] + show "False" by simp + qed + thus ?case by auto +qed auto + +lemma minusinf_repeats: + assumes d: "d\ p d" and linp: "iszlfm p" + shows "Ifm bbs ((x - k*d)#bs) (minusinf p) = Ifm bbs (x #bs) (minusinf p)" +using linp d +proof(induct p rule: iszlfm.induct) + case (9 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ + hence "\ k. d=i*k" by (simp add: dvd_def) + then obtain "di" where di_def: "d=i*di" by blast + show ?case + proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="x - k * d" and b'="x"] right_diff_distrib, rule iffI) + assume + "i dvd c * x - c*(k*d) + Inum (x # bs) e" + (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt") + hence "\ (l::int). ?rt = i * l" by (simp add: dvd_def) + hence "\ (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" + by (simp add: algebra_simps di_def) + hence "\ (l::int). c*x+ ?I x e = i*(l + c*k*di)" + by (simp add: algebra_simps) + hence "\ (l::int). c*x+ ?I x e = i*l" by blast + thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) + next + assume + "i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e") + hence "\ (l::int). c*x+?e = i*l" by (simp add: dvd_def) + hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp + hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def) + hence "\ (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: algebra_simps) + hence "\ (l::int). c*x - c * (k*d) +?e = i*l" + by blast + thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def) + qed +next + case (10 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ + hence "\ k. d=i*k" by (simp add: dvd_def) + then obtain "di" where di_def: "d=i*di" by blast + show ?case + proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="x - k * d" and b'="x"] right_diff_distrib, rule iffI) + assume + "i dvd c * x - c*(k*d) + Inum (x # bs) e" + (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt") + hence "\ (l::int). ?rt = i * l" by (simp add: dvd_def) + hence "\ (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" + by (simp add: algebra_simps di_def) + hence "\ (l::int). c*x+ ?I x e = i*(l + c*k*di)" + by (simp add: algebra_simps) + hence "\ (l::int). c*x+ ?I x e = i*l" by blast + thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) + next + assume + "i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e") + hence "\ (l::int). c*x+?e = i*l" by (simp add: dvd_def) + hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp + hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def) + hence "\ (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: algebra_simps) + hence "\ (l::int). c*x - c * (k*d) +?e = i*l" + by blast + thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def) + qed +qed (auto simp add: gr0_conv_Suc numbound0_I[where bs="bs" and b="x - k*d" and b'="x"]) + +lemma mirror\\: + assumes lp: "iszlfm p" + shows "(Inum (i#bs)) ` set (\ p) = (Inum (i#bs)) ` set (\ (mirror p))" +using lp +by (induct p rule: mirror.induct, auto) + +lemma mirror: + assumes lp: "iszlfm p" + shows "Ifm bbs (x#bs) (mirror p) = Ifm bbs ((- x)#bs) p" +using lp +proof(induct p rule: iszlfm.induct) + case (9 j c e) hence nb: "numbound0 e" by simp + have "Ifm bbs (x#bs) (mirror (Dvd j (CN 0 c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp + also have "\ = (j dvd (- (c*x - ?e)))" + by (simp only: zdvd_zminus_iff) + also have "\ = (j dvd (c* (- x)) + ?e)" + apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib) + by (simp add: algebra_simps) + also have "\ = Ifm bbs ((- x)#bs) (Dvd j (CN 0 c e))" + using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"] + by simp + finally show ?case . +next + case (10 j c e) hence nb: "numbound0 e" by simp + have "Ifm bbs (x#bs) (mirror (Dvd j (CN 0 c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp + also have "\ = (j dvd (- (c*x - ?e)))" + by (simp only: zdvd_zminus_iff) + also have "\ = (j dvd (c* (- x)) + ?e)" + apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib) + by (simp add: algebra_simps) + also have "\ = Ifm bbs ((- x)#bs) (Dvd j (CN 0 c e))" + using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"] + by simp + finally show ?case by simp +qed (auto simp add: numbound0_I[where bs="bs" and b="x" and b'="- x"] gr0_conv_Suc) + +lemma mirror_l: "iszlfm p \ d\ p 1 + \ iszlfm (mirror p) \ d\ (mirror p) 1" +by (induct p rule: mirror.induct, auto) + +lemma mirror_\: "iszlfm p \ \ (mirror p) = \ p" +by (induct p rule: mirror.induct,auto) + +lemma \_numbound0: assumes lp: "iszlfm p" + shows "\ b\ set (\ p). numbound0 b" + using lp by (induct p rule: \.induct,auto) + +lemma d\_mono: + assumes linp: "iszlfm p" + and dr: "d\ p l" + and d: "l dvd l'" + shows "d\ p l'" +using dr linp zdvd_trans[where n="l" and k="l'", simplified d] +by (induct p rule: iszlfm.induct) simp_all + +lemma \_l: assumes lp: "iszlfm p" + shows "\ b\ set (\ p). numbound0 b" +using lp +by(induct p rule: \.induct, auto) + +lemma \: + assumes linp: "iszlfm p" + shows "\ p > 0 \ d\ p (\ p)" +using linp +proof(induct p rule: iszlfm.induct) + case (1 p q) + from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp + from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp + from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] + d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] + dl1 dl2 show ?case by (auto simp add: zlcm_pos) +next + case (2 p q) + from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp + from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp + from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] + d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] + dl1 dl2 show ?case by (auto simp add: zlcm_pos) +qed (auto simp add: zlcm_pos) + +lemma a\: assumes linp: "iszlfm p" and d: "d\ p l" and lp: "l > 0" + shows "iszlfm (a\ p l) \ d\ (a\ p l) 1 \ (Ifm bbs (l*x #bs) (a\ p l) = Ifm bbs (x#bs) p)" +using linp d +proof (induct p rule: iszlfm.induct) + case (5 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(l*x + (l div c) * Inum (x # bs) e < 0) = + ((c * (l div c)) * x + (l div c) * Inum (x # bs) e < 0)" + by simp + also have "\ = ((l div c) * (c*x + Inum (x # bs) e) < (l div c) * 0)" by (simp add: algebra_simps) + also have "\ = (c*x + Inum (x # bs) e < 0)" + using mult_less_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] be by simp +next + case (6 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(l*x + (l div c) * Inum (x# bs) e \ 0) = + ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \ 0)" + by simp + also have "\ = ((l div c) * (c * x + Inum (x # bs) e) \ ((l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (c*x + Inum (x # bs) e \ 0)" + using mult_le_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] be by simp +next + case (7 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(l*x + (l div c)* Inum (x # bs) e > 0) = + ((c * (l div c)) * x + (l div c) * Inum (x # bs) e > 0)" + by simp + also have "\ = ((l div c) * (c * x + Inum (x # bs) e) > ((l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (c * x + Inum (x # bs) e > 0)" + using zero_less_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be by simp +next + case (8 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(l*x + (l div c)* Inum (x # bs) e \ 0) = + ((c*(l div c))*x + (l div c)* Inum (x # bs) e \ 0)" + by simp + also have "\ = ((l div c)*(c*x + Inum (x # bs) e) \ ((l div c)) * 0)" + by (simp add: algebra_simps) + also have "\ = (c*x + Inum (x # bs) e \ 0)" using ldcp + zero_le_mult_iff [where a="l div c" and b="c*x + Inum (x # bs) e"] by simp + finally show ?case using be numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] + by simp +next + case (3 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(l * x + (l div c) * Inum (x # bs) e = 0) = + ((c * (l div c)) * x + (l div c) * Inum (x # bs) e = 0)" + by simp + also have "\ = ((l div c) * (c * x + Inum (x # bs) e) = ((l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (c * x + Inum (x # bs) e = 0)" + using mult_eq_0_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be by simp +next + case (4 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(l * x + (l div c) * Inum (x # bs) e \ 0) = + ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \ 0)" + by simp + also have "\ = ((l div c) * (c * x + Inum (x # bs) e) \ ((l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (c * x + Inum (x # bs) e \ 0)" + using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be by simp +next + case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and jp: "j > 0" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(\ (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\ (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)" by simp + also have "\ = (\ (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: algebra_simps) + also fix k have "\ = (\ (k::int). c * x + Inum (x # bs) e - j * k = 0)" + using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp + also have "\ = (\ (k::int). c * x + Inum (x # bs) e = j * k)" by simp + 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) +next + case (10 j c e) hence cp: "c>0" and be: "numbound0 e" and jp: "j > 0" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(\ (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\ (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)" by simp + also have "\ = (\ (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: algebra_simps) + also fix k have "\ = (\ (k::int). c * x + Inum (x # bs) e - j * k = 0)" + using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp + also have "\ = (\ (k::int). c * x + Inum (x # bs) e = j * k)" by simp + 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) +qed (auto simp add: gr0_conv_Suc numbound0_I[where bs="bs" and b="(l * x)" and b'="x"]) + +lemma a\_ex: assumes linp: "iszlfm p" and d: "d\ p l" and lp: "l>0" + shows "(\ x. l dvd x \ Ifm bbs (x #bs) (a\ p l)) = (\ (x::int). Ifm bbs (x#bs) p)" + (is "(\ x. l dvd x \ ?P x) = (\ x. ?P' x)") +proof- + have "(\ x. l dvd x \ ?P x) = (\ (x::int). ?P (l*x))" + using unity_coeff_ex[where l="l" and P="?P", simplified] by simp + also have "\ = (\ (x::int). ?P' x)" using a\[OF linp d lp] by simp + finally show ?thesis . +qed + +lemma \: + assumes lp: "iszlfm p" + and u: "d\ p 1" + and d: "d\ p d" + and dp: "d > 0" + and nob: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). x = b + j)" + and p: "Ifm bbs (x#bs) p" (is "?P x") + shows "?P (x - d)" +using lp u d dp nob p +proof(induct p rule: iszlfm.induct) + case (5 c e) hence c1: "c=1" and bn:"numbound0 e" by simp+ + with dp p c1 numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] prems + show ?case by simp +next + case (6 c e) hence c1: "c=1" and bn:"numbound0 e" by simp+ + with dp p c1 numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] prems + show ?case by simp +next + case (7 c e) hence p: "Ifm bbs (x #bs) (Gt (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" by simp+ + let ?e = "Inum (x # bs) e" + {assume "(x-d) +?e > 0" hence ?case using c1 + numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] by simp} + moreover + {assume H: "\ (x-d) + ?e > 0" + let ?v="Neg e" + have vb: "?v \ set (\ (Gt (CN 0 c e)))" by simp + from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="x" and bs="bs"]] + have nob: "\ (\ j\ {1 ..d}. x = - ?e + j)" by auto + from H p have "x + ?e > 0 \ x + ?e \ d" by (simp add: c1) + hence "x + ?e \ 1 \ x + ?e \ d" by simp + hence "\ (j::int) \ {1 .. d}. j = x + ?e" by simp + hence "\ (j::int) \ {1 .. d}. x = (- ?e + j)" + by (simp add: algebra_simps) + with nob have ?case by auto} + ultimately show ?case by blast +next + case (8 c e) hence p: "Ifm bbs (x #bs) (Ge (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" + by simp+ + let ?e = "Inum (x # bs) e" + {assume "(x-d) +?e \ 0" hence ?case using c1 + numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] + by simp} + moreover + {assume H: "\ (x-d) + ?e \ 0" + let ?v="Sub (C -1) e" + have vb: "?v \ set (\ (Ge (CN 0 c e)))" by simp + from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="x" and bs="bs"]] + have nob: "\ (\ j\ {1 ..d}. x = - ?e - 1 + j)" by auto + from H p have "x + ?e \ 0 \ x + ?e < d" by (simp add: c1) + hence "x + ?e +1 \ 1 \ x + ?e + 1 \ d" by simp + hence "\ (j::int) \ {1 .. d}. j = x + ?e + 1" by simp + hence "\ (j::int) \ {1 .. d}. x= - ?e - 1 + j" by (simp add: algebra_simps) + with nob have ?case by simp } + ultimately show ?case by blast +next + case (3 c e) hence p: "Ifm bbs (x #bs) (Eq (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ + let ?e = "Inum (x # bs) e" + let ?v="(Sub (C -1) e)" + have vb: "?v \ set (\ (Eq (CN 0 c e)))" by simp + from p have "x= - ?e" by (simp add: c1) with prems(11) show ?case using dp + by simp (erule ballE[where x="1"], + simp_all add:algebra_simps numbound0_I[OF bn,where b="x"and b'="a"and bs="bs"]) +next + case (4 c e)hence p: "Ifm bbs (x #bs) (NEq (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ + let ?e = "Inum (x # bs) e" + let ?v="Neg e" + have vb: "?v \ set (\ (NEq (CN 0 c e)))" by simp + {assume "x - d + Inum (((x -d)) # bs) e \ 0" + hence ?case by (simp add: c1)} + moreover + {assume H: "x - d + Inum (((x -d)) # bs) e = 0" + hence "x = - Inum (((x -d)) # bs) e + d" by simp + hence "x = - Inum (a # bs) e + d" + by (simp add: numbound0_I[OF bn,where b="x - d"and b'="a"and bs="bs"]) + with prems(11) have ?case using dp by simp} + ultimately show ?case by blast +next + case (9 j c e) hence p: "Ifm bbs (x #bs) (Dvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ + let ?e = "Inum (x # bs) e" + from prems have id: "j dvd d" by simp + from c1 have "?p x = (j dvd (x+ ?e))" by simp + also have "\ = (j dvd x - d + ?e)" + using zdvd_period[OF id, where x="x" and c="-1" and t="?e"] by simp + finally show ?case + using numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] c1 p by simp +next + case (10 j c e) hence p: "Ifm bbs (x #bs) (NDvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ + let ?e = "Inum (x # bs) e" + from prems have id: "j dvd d" by simp + from c1 have "?p x = (\ j dvd (x+ ?e))" by simp + also have "\ = (\ j dvd x - d + ?e)" + using zdvd_period[OF id, where x="x" and c="-1" and t="?e"] by simp + finally show ?case using numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] c1 p by simp +qed (auto simp add: numbound0_I[where bs="bs" and b="(x - d)" and b'="x"] gr0_conv_Suc) + +lemma \': + assumes lp: "iszlfm p" + and u: "d\ p 1" + and d: "d\ p d" + and dp: "d > 0" + shows "\ x. \(\(j::int) \ {1 .. d}. \ b\ set(\ p). Ifm bbs ((Inum (a#bs) b + j) #bs) p) \ Ifm bbs (x#bs) p \ Ifm bbs ((x - d)#bs) p" (is "\ x. ?b \ ?P x \ ?P (x - d)") +proof(clarify) + fix x + assume nb:"?b" and px: "?P x" + hence nb2: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). x = b + j)" + by auto + from \[OF lp u d dp nb2 px] show "?P (x -d )" . +qed +lemma cpmi_eq: "0 < D \ (EX z::int. ALL x. x < z --> (P x = P1 x)) +==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) +==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D)))) +==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))" +apply(rule iffI) +prefer 2 +apply(drule minusinfinity) +apply assumption+ +apply(fastsimp) +apply clarsimp +apply(subgoal_tac "!!k. 0<=k \ !x. P x \ P (x - k*D)") +apply(frule_tac x = x and z=z in decr_lemma) +apply(subgoal_tac "P1(x - (\x - z\ + 1) * D)") +prefer 2 +apply(subgoal_tac "0 <= (\x - z\ + 1)") +prefer 2 apply arith + apply fastsimp +apply(drule (1) periodic_finite_ex) +apply blast +apply(blast dest:decr_mult_lemma) +done + +theorem cp_thm: + assumes lp: "iszlfm p" + and u: "d\ p 1" + and d: "d\ p d" + and dp: "d > 0" + shows "(\ (x::int). Ifm bbs (x #bs) p) = (\ j\ {1.. d}. Ifm bbs (j #bs) (minusinf p) \ (\ b \ set (\ p). Ifm bbs ((Inum (i#bs) b + j) #bs) p))" + (is "(\ (x::int). ?P (x)) = (\ j\ ?D. ?M j \ (\ b\ ?B. ?P (?I b + j)))") +proof- + from minusinf_inf[OF lp u] + have th: "\(z::int). \xj\?D. \b\ ?B. ?P (?I b +j)) = (\ j \ ?D. \ b \ ?B'. ?P (b + j))" by auto + hence th2: "\ x. \ (\ j \ ?D. \ b \ ?B'. ?P ((b + j))) \ ?P (x) \ ?P ((x - d))" + using \'[OF lp u d dp, where a="i" and bbs = "bbs"] by blast + from minusinf_repeats[OF d lp] + have th3: "\ x k. ?M x = ?M (x-k*d)" by simp + from cpmi_eq[OF dp th th2 th3] BB' show ?thesis by blast +qed + + (* Implement the right hand sides of Cooper's theorem and Ferrante and Rackoff. *) +lemma mirror_ex: + assumes lp: "iszlfm p" + shows "(\ x. Ifm bbs (x#bs) (mirror p)) = (\ x. Ifm bbs (x#bs) p)" + (is "(\ x. ?I x ?mp) = (\ x. ?I x p)") +proof(auto) + fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast + thus "\ x. ?I x p" by blast +next + fix x assume "?I x p" hence "?I (- x) ?mp" + using mirror[OF lp, where x="- x", symmetric] by auto + thus "\ x. ?I x ?mp" by blast +qed + + +lemma cp_thm': + assumes lp: "iszlfm p" + and up: "d\ p 1" and dd: "d\ p d" and dp: "d > 0" + shows "(\ x. Ifm bbs (x#bs) p) = ((\ j\ {1 .. d}. Ifm bbs (j#bs) (minusinf p)) \ (\ j\ {1.. d}. \ b\ (Inum (i#bs)) ` set (\ p). Ifm bbs ((b+j)#bs) p))" + using cp_thm[OF lp up dd dp,where i="i"] by auto + +constdefs unit:: "fm \ fm \ num list \ int" + "unit p \ (let p' = zlfm p ; l = \ p' ; q = And (Dvd l (CN 0 1 (C 0))) (a\ p' l); d = \ q; + B = remdups (map simpnum (\ q)) ; a = remdups (map simpnum (\ q)) + in if length B \ length a then (q,B,d) else (mirror q, a,d))" + +lemma unit: assumes qf: "qfree p" + shows "\ q B d. unit p = (q,B,d) \ ((\ x. Ifm bbs (x#bs) p) = (\ x. Ifm bbs (x#bs) q)) \ (Inum (i#bs)) ` set B = (Inum (i#bs)) ` set (\ q) \ d\ q 1 \ d\ q d \ d >0 \ iszlfm q \ (\ b\ set B. numbound0 b)" +proof- + fix q B d + assume qBd: "unit p = (q,B,d)" + let ?thes = "((\ x. Ifm bbs (x#bs) p) = (\ x. Ifm bbs (x#bs) q)) \ + Inum (i#bs) ` set B = Inum (i#bs) ` set (\ q) \ + d\ q 1 \ d\ q d \ 0 < d \ iszlfm q \ (\ b\ set B. numbound0 b)" + let ?I = "\ x p. Ifm bbs (x#bs) p" + let ?p' = "zlfm p" + let ?l = "\ ?p'" + let ?q = "And (Dvd ?l (CN 0 1 (C 0))) (a\ ?p' ?l)" + let ?d = "\ ?q" + let ?B = "set (\ ?q)" + let ?B'= "remdups (map simpnum (\ ?q))" + let ?A = "set (\ ?q)" + let ?A'= "remdups (map simpnum (\ ?q))" + from conjunct1[OF zlfm_I[OF qf, where bs="bs"]] + have pp': "\ i. ?I i ?p' = ?I i p" by auto + from conjunct2[OF zlfm_I[OF qf, where bs="bs" and i="i"]] + have lp': "iszlfm ?p'" . + from lp' \[where p="?p'"] have lp: "?l >0" and dl: "d\ ?p' ?l" by auto + from a\_ex[where p="?p'" and l="?l" and bs="bs", OF lp' dl lp] pp' + have pq_ex:"(\ (x::int). ?I x p) = (\ x. ?I x ?q)" by simp + from lp' lp a\[OF lp' dl lp] have lq:"iszlfm ?q" and uq: "d\ ?q 1" by auto + from \[OF lq] have dp:"?d >0" and dd: "d\ ?q ?d" by blast+ + let ?N = "\ t. Inum (i#bs) t" + have "?N ` set ?B' = ((?N o simpnum) ` ?B)" by auto + also have "\ = ?N ` ?B" using simpnum_ci[where bs="i#bs"] by auto + finally have BB': "?N ` set ?B' = ?N ` ?B" . + have "?N ` set ?A' = ((?N o simpnum) ` ?A)" by auto + also have "\ = ?N ` ?A" using simpnum_ci[where bs="i#bs"] by auto + finally have AA': "?N ` set ?A' = ?N ` ?A" . + from \_numbound0[OF lq] have B_nb:"\ b\ set ?B'. numbound0 b" + by (simp add: simpnum_numbound0) + from \_l[OF lq] have A_nb: "\ b\ set ?A'. numbound0 b" + by (simp add: simpnum_numbound0) + {assume "length ?B' \ length ?A'" + hence q:"q=?q" and "B = ?B'" and d:"d = ?d" + using qBd by (auto simp add: Let_def unit_def) + with BB' B_nb have b: "?N ` (set B) = ?N ` set (\ q)" + and bn: "\b\ set B. numbound0 b" by simp+ + with pq_ex dp uq dd lq q d have ?thes by simp} + moreover + {assume "\ (length ?B' \ length ?A')" + hence q:"q=mirror ?q" and "B = ?A'" and d:"d = ?d" + using qBd by (auto simp add: Let_def unit_def) + with AA' mirror\\[OF lq] A_nb have b:"?N ` (set B) = ?N ` set (\ q)" + and bn: "\b\ set B. numbound0 b" by simp+ + from mirror_ex[OF lq] pq_ex q + have pqm_eq:"(\ (x::int). ?I x p) = (\ (x::int). ?I x q)" by simp + from lq uq q mirror_l[where p="?q"] + have lq': "iszlfm q" and uq: "d\ q 1" by auto + from \[OF lq'] mirror_\[OF lq] q d have dq:"d\ q d " by auto + from pqm_eq b bn uq lq' dp dq q dp d have ?thes by simp + } + ultimately show ?thes by blast +qed + (* Cooper's Algorithm *) + +constdefs cooper :: "fm \ fm" + "cooper p \ + (let (q,B,d) = unit p; js = iupt 1 d; + mq = simpfm (minusinf q); + md = evaldjf (\ j. simpfm (subst0 (C j) mq)) js + in if md = T then T else + (let qd = evaldjf (\ (b,j). simpfm (subst0 (Add b (C j)) q)) + [(b,j). b\B,j\js] + in decr (disj md qd)))" +lemma cooper: assumes qf: "qfree p" + shows "((\ x. Ifm bbs (x#bs) p) = (Ifm bbs bs (cooper p))) \ qfree (cooper p)" + (is "(?lhs = ?rhs) \ _") +proof- + let ?I = "\ x p. Ifm bbs (x#bs) p" + let ?q = "fst (unit p)" + let ?B = "fst (snd(unit p))" + let ?d = "snd (snd (unit p))" + let ?js = "iupt 1 ?d" + let ?mq = "minusinf ?q" + let ?smq = "simpfm ?mq" + let ?md = "evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js" + fix i + let ?N = "\ t. Inum (i#bs) t" + let ?Bjs = "[(b,j). b\?B,j\?js]" + let ?qd = "evaldjf (\ (b,j). simpfm (subst0 (Add b (C j)) ?q)) ?Bjs" + have qbf:"unit p = (?q,?B,?d)" by simp + from unit[OF qf qbf] have pq_ex: "(\(x::int). ?I x p) = (\ (x::int). ?I x ?q)" and + B:"?N ` set ?B = ?N ` set (\ ?q)" and + uq:"d\ ?q 1" and dd: "d\ ?q ?d" and dp: "?d > 0" and + lq: "iszlfm ?q" and + Bn: "\ b\ set ?B. numbound0 b" by auto + from zlin_qfree[OF lq] have qfq: "qfree ?q" . + from simpfm_qf[OF minusinf_qfree[OF qfq]] have qfmq: "qfree ?smq". + have jsnb: "\ j \ set ?js. numbound0 (C j)" by simp + hence "\ j\ set ?js. bound0 (subst0 (C j) ?smq)" + by (auto simp only: subst0_bound0[OF qfmq]) + hence th: "\ j\ set ?js. bound0 (simpfm (subst0 (C j) ?smq))" + by (auto simp add: simpfm_bound0) + from evaldjf_bound0[OF th] have mdb: "bound0 ?md" by simp + from Bn jsnb have "\ (b,j) \ set ?Bjs. numbound0 (Add b (C j))" + by simp + hence "\ (b,j) \ set ?Bjs. bound0 (subst0 (Add b (C j)) ?q)" + using subst0_bound0[OF qfq] by blast + hence "\ (b,j) \ set ?Bjs. bound0 (simpfm (subst0 (Add b (C j)) ?q))" + using simpfm_bound0 by blast + hence th': "\ x \ set ?Bjs. bound0 ((\ (b,j). simpfm (subst0 (Add b (C j)) ?q)) x)" + by auto + from evaldjf_bound0 [OF th'] have qdb: "bound0 ?qd" by simp + from mdb qdb + have mdqdb: "bound0 (disj ?md ?qd)" by (simp only: disj_def, cases "?md=T \ ?qd=T", simp_all) + from trans [OF pq_ex cp_thm'[OF lq uq dd dp,where i="i"]] B + have "?lhs = (\ j\ {1.. ?d}. ?I j ?mq \ (\ b\ ?N ` set ?B. Ifm bbs ((b+ j)#bs) ?q))" by auto + also have "\ = (\ j\ {1.. ?d}. ?I j ?mq \ (\ b\ set ?B. Ifm bbs ((?N b+ j)#bs) ?q))" by simp + also have "\ = ((\ j\ {1.. ?d}. ?I j ?mq ) \ (\ j\ {1.. ?d}. \ b\ set ?B. Ifm bbs ((?N (Add b (C j)))#bs) ?q))" by (simp only: Inum.simps) blast + also have "\ = ((\ j\ {1.. ?d}. ?I j ?smq ) \ (\ j\ {1.. ?d}. \ b\ set ?B. Ifm bbs ((?N (Add b (C j)))#bs) ?q))" by (simp add: simpfm) + also have "\ = ((\ j\ set ?js. (\ j. ?I i (simpfm (subst0 (C j) ?smq))) j) \ (\ j\ set ?js. \ b\ set ?B. Ifm bbs ((?N (Add b (C j)))#bs) ?q))" + by (simp only: simpfm subst0_I[OF qfmq] iupt_set) auto + also have "\ = (?I i (evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js) \ (\ j\ set ?js. \ b\ set ?B. ?I i (subst0 (Add b (C j)) ?q)))" + by (simp only: evaldjf_ex subst0_I[OF qfq]) + also have "\= (?I i ?md \ (\ (b,j) \ set ?Bjs. (\ (b,j). ?I i (simpfm (subst0 (Add b (C j)) ?q))) (b,j)))" + by (simp only: simpfm set_concat set_map concat_map_singleton UN_simps) blast + also have "\ = (?I i ?md \ (?I i (evaldjf (\ (b,j). simpfm (subst0 (Add b (C j)) ?q)) ?Bjs)))" + by (simp only: evaldjf_ex[where bs="i#bs" and f="\ (b,j). simpfm (subst0 (Add b (C j)) ?q)" and ps="?Bjs"]) (auto simp add: split_def) + finally have mdqd: "?lhs = (?I i ?md \ ?I i ?qd)" by simp + also have "\ = (?I i (disj ?md ?qd))" by (simp add: disj) + also have "\ = (Ifm bbs bs (decr (disj ?md ?qd)))" by (simp only: decr [OF mdqdb]) + finally have mdqd2: "?lhs = (Ifm bbs bs (decr (disj ?md ?qd)))" . + {assume mdT: "?md = T" + hence cT:"cooper p = T" + by (simp only: cooper_def unit_def split_def Let_def if_True) simp + from mdT have lhs:"?lhs" using mdqd by simp + from mdT have "?rhs" by (simp add: cooper_def unit_def split_def) + with lhs cT have ?thesis by simp } + moreover + {assume mdT: "?md \ T" hence "cooper p = decr (disj ?md ?qd)" + by (simp only: cooper_def unit_def split_def Let_def if_False) + with mdqd2 decr_qf[OF mdqdb] have ?thesis by simp } + ultimately show ?thesis by blast +qed + +definition pa :: "fm \ fm" where + "pa p = qelim (prep p) cooper" + +theorem mirqe: "(Ifm bbs bs (pa p) = Ifm bbs bs p) \ qfree (pa p)" + using qelim_ci cooper prep by (auto simp add: pa_def) + +definition + cooper_test :: "unit \ fm" +where + "cooper_test u = pa (E (A (Imp (Ge (Sub (Bound 0) (Bound 1))) + (E (E (Eq (Sub (Add (Mul 3 (Bound 1)) (Mul 5 (Bound 0))) + (Bound 2))))))))" + +ML {* @{code cooper_test} () *} + +(* +code_reserved SML oo +export_code pa in SML module_name GeneratedCooper file "~~/src/HOL/Tools/Qelim/raw_generated_cooper.ML" +*) + +oracle linzqe_oracle = {* +let + +fun num_of_term vs (t as Free (xn, xT)) = (case AList.lookup (op =) vs t + of NONE => error "Variable not found in the list!" + | SOME n => @{code Bound} n) + | num_of_term vs @{term "0::int"} = @{code C} 0 + | num_of_term vs @{term "1::int"} = @{code C} 1 + | num_of_term vs (@{term "number_of :: int \ int"} $ t) = @{code C} (HOLogic.dest_numeral t) + | num_of_term vs (Bound i) = @{code Bound} i + | num_of_term vs (@{term "uminus :: int \ int"} $ t') = @{code Neg} (num_of_term vs t') + | num_of_term vs (@{term "op + :: int \ int \ int"} $ t1 $ t2) = + @{code Add} (num_of_term vs t1, num_of_term vs t2) + | num_of_term vs (@{term "op - :: int \ int \ int"} $ t1 $ t2) = + @{code Sub} (num_of_term vs t1, num_of_term vs t2) + | num_of_term vs (@{term "op * :: int \ int \ int"} $ t1 $ t2) = + (case try HOLogic.dest_number t1 + of SOME (_, i) => @{code Mul} (i, num_of_term vs t2) + | NONE => (case try HOLogic.dest_number t2 + of SOME (_, i) => @{code Mul} (i, num_of_term vs t1) + | NONE => error "num_of_term: unsupported multiplication")) + | num_of_term vs t = error ("num_of_term: unknown term " ^ Syntax.string_of_term @{context} t); + +fun fm_of_term ps vs @{term True} = @{code T} + | fm_of_term ps vs @{term False} = @{code F} + | fm_of_term ps vs (@{term "op < :: int \ int \ bool"} $ t1 $ t2) = + @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) + | fm_of_term ps vs (@{term "op \ :: int \ int \ bool"} $ t1 $ t2) = + @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) + | fm_of_term ps vs (@{term "op = :: int \ int \ bool"} $ t1 $ t2) = + @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) + | fm_of_term ps vs (@{term "op dvd :: int \ int \ bool"} $ t1 $ t2) = + (case try HOLogic.dest_number t1 + of SOME (_, i) => @{code Dvd} (i, num_of_term vs t2) + | NONE => error "num_of_term: unsupported dvd") + | fm_of_term ps vs (@{term "op = :: bool \ bool \ bool"} $ t1 $ t2) = + @{code Iff} (fm_of_term ps vs t1, fm_of_term ps vs t2) + | fm_of_term ps vs (@{term "op &"} $ t1 $ t2) = + @{code And} (fm_of_term ps vs t1, fm_of_term ps vs t2) + | fm_of_term ps vs (@{term "op |"} $ t1 $ t2) = + @{code Or} (fm_of_term ps vs t1, fm_of_term ps vs t2) + | fm_of_term ps vs (@{term "op -->"} $ t1 $ t2) = + @{code Imp} (fm_of_term ps vs t1, fm_of_term ps vs t2) + | fm_of_term ps vs (@{term "Not"} $ t') = + @{code NOT} (fm_of_term ps vs t') + | fm_of_term ps vs (Const ("Ex", _) $ Abs (xn, xT, p)) = + let + val (xn', p') = variant_abs (xn, xT, p); + val vs' = (Free (xn', xT), 0) :: map (fn (v, n) => (v, n + 1)) vs; + in @{code E} (fm_of_term ps vs' p) end + | fm_of_term ps vs (Const ("All", _) $ Abs (xn, xT, p)) = + let + val (xn', p') = variant_abs (xn, xT, p); + val vs' = (Free (xn', xT), 0) :: map (fn (v, n) => (v, n + 1)) vs; + in @{code A} (fm_of_term ps vs' p) end + | fm_of_term ps vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); + +fun term_of_num vs (@{code C} i) = HOLogic.mk_number HOLogic.intT i + | term_of_num vs (@{code Bound} n) = fst (the (find_first (fn (_, m) => n = m) vs)) + | term_of_num vs (@{code Neg} t') = @{term "uminus :: int \ int"} $ term_of_num vs t' + | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: int \ int \ int"} $ + term_of_num vs t1 $ term_of_num vs t2 + | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: int \ int \ int"} $ + term_of_num vs t1 $ term_of_num vs t2 + | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: int \ int \ int"} $ + term_of_num vs (@{code C} i) $ term_of_num vs t2 + | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)); + +fun term_of_fm ps vs @{code T} = HOLogic.true_const + | term_of_fm ps vs @{code F} = HOLogic.false_const + | term_of_fm ps vs (@{code Lt} t) = + @{term "op < :: int \ int \ bool"} $ term_of_num vs t $ @{term "0::int"} + | term_of_fm ps vs (@{code Le} t) = + @{term "op \ :: int \ int \ bool"} $ term_of_num vs t $ @{term "0::int"} + | term_of_fm ps vs (@{code Gt} t) = + @{term "op < :: int \ int \ bool"} $ @{term "0::int"} $ term_of_num vs t + | term_of_fm ps vs (@{code Ge} t) = + @{term "op \ :: int \ int \ bool"} $ @{term "0::int"} $ term_of_num vs t + | term_of_fm ps vs (@{code Eq} t) = + @{term "op = :: int \ int \ bool"} $ term_of_num vs t $ @{term "0::int"} + | term_of_fm ps vs (@{code NEq} t) = + term_of_fm ps vs (@{code NOT} (@{code Eq} t)) + | term_of_fm ps vs (@{code Dvd} (i, t)) = + @{term "op dvd :: int \ int \ bool"} $ term_of_num vs (@{code C} i) $ term_of_num vs t + | term_of_fm ps vs (@{code NDvd} (i, t)) = + term_of_fm ps vs (@{code NOT} (@{code Dvd} (i, t))) + | term_of_fm ps vs (@{code NOT} t') = + HOLogic.Not $ term_of_fm ps vs t' + | term_of_fm ps vs (@{code And} (t1, t2)) = + HOLogic.conj $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 + | term_of_fm ps vs (@{code Or} (t1, t2)) = + HOLogic.disj $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 + | term_of_fm ps vs (@{code Imp} (t1, t2)) = + HOLogic.imp $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 + | term_of_fm ps vs (@{code Iff} (t1, t2)) = + @{term "op = :: bool \ bool \ bool"} $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 + | term_of_fm ps vs (@{code Closed} n) = (fst o the) (find_first (fn (_, m) => m = n) ps) + | term_of_fm ps vs (@{code NClosed} n) = term_of_fm ps vs (@{code NOT} (@{code Closed} n)); + +fun term_bools acc t = + let + val is_op = member (op =) [@{term "op &"}, @{term "op |"}, @{term "op -->"}, @{term "op = :: bool => _"}, + @{term "op = :: int => _"}, @{term "op < :: int => _"}, + @{term "op <= :: int => _"}, @{term "Not"}, @{term "All :: (int => _) => _"}, + @{term "Ex :: (int => _) => _"}, @{term "True"}, @{term "False"}] + fun is_ty t = not (fastype_of t = HOLogic.boolT) + in case t + of (l as f $ a) $ b => if is_ty t orelse is_op t then term_bools (term_bools acc l)b + else insert (op aconv) t acc + | f $ a => if is_ty t orelse is_op t then term_bools (term_bools acc f) a + else insert (op aconv) t acc + | Abs p => term_bools acc (snd (variant_abs p)) + | _ => if is_ty t orelse is_op t then acc else insert (op aconv) t acc + end; + +in fn ct => + let + val thy = Thm.theory_of_cterm ct; + val t = Thm.term_of ct; + val fs = OldTerm.term_frees t; + val bs = term_bools [] t; + val vs = fs ~~ (0 upto (length fs - 1)) + val ps = bs ~~ (0 upto (length bs - 1)) + val t' = (term_of_fm ps vs o @{code pa} o fm_of_term ps vs) t; + in (Thm.cterm_of thy o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end +end; +*} + +use "cooper_tac.ML" +setup "Cooper_Tac.setup" + +text {* Tests *} + +lemma "\ (j::int). \ x\j. (\ a b. x = 3*a+5*b)" + by cooper + +lemma "ALL (x::int) >=8. EX i j. 5*i + 3*j = x" + by cooper + +theorem "(\(y::int). 3 dvd y) ==> \(x::int). b < x --> a \ x" + by cooper + +theorem "!! (y::int) (z::int) (n::int). 3 dvd z ==> 2 dvd (y::int) ==> + (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" + by cooper + +theorem "!! (y::int) (z::int) n. Suc(n::nat) < 6 ==> 3 dvd z ==> + 2 dvd (y::int) ==> (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" + by cooper + +theorem "\(x::nat). \(y::nat). (0::nat) \ 5 --> y = 5 + x " + by cooper + +lemma "ALL (x::int) >=8. EX i j. 5*i + 3*j = x" + by cooper + +lemma "ALL (y::int) (z::int) (n::int). 3 dvd z --> 2 dvd (y::int) --> (EX (x::int). 2*x = y) & (EX (k::int). 3*k = z)" + by cooper + +lemma "ALL(x::int) y. x < y --> 2 * x + 1 < 2 * y" + by cooper + +lemma "ALL(x::int) y. 2 * x + 1 ~= 2 * y" + by cooper + +lemma "EX(x::int) y. 0 < x & 0 <= y & 3 * x - 5 * y = 1" + by cooper + +lemma "~ (EX(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)" + by cooper + +lemma "ALL(x::int). (2 dvd x) --> (EX(y::int). x = 2*y)" + by cooper + +lemma "ALL(x::int). (2 dvd x) = (EX(y::int). x = 2*y)" + by cooper + +lemma "ALL(x::int). ((2 dvd x) = (ALL(y::int). x ~= 2*y + 1))" + by cooper + +lemma "~ (ALL(x::int). ((2 dvd x) = (ALL(y::int). x ~= 2*y+1) | (EX(q::int) (u::int) i. 3*i + 2*q - u < 17) --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))" + by cooper + +lemma "~ (ALL(i::int). 4 <= i --> (EX x y. 0 <= x & 0 <= y & 3 * x + 5 * y = i))" + by cooper + +lemma "EX j. ALL (x::int) >= j. EX i j. 5*i + 3*j = x" + by cooper + +theorem "(\(y::int). 3 dvd y) ==> \(x::int). b < x --> a \ x" + by cooper + +theorem "!! (y::int) (z::int) (n::int). 3 dvd z ==> 2 dvd (y::int) ==> + (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" + by cooper + +theorem "!! (y::int) (z::int) n. Suc(n::nat) < 6 ==> 3 dvd z ==> + 2 dvd (y::int) ==> (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" + by cooper + +theorem "\(x::nat). \(y::nat). (0::nat) \ 5 --> y = 5 + x " + by cooper + +theorem "\(x::nat). \(y::nat). y = 5 + x | x div 6 + 1= 2" + by cooper + +theorem "\(x::int). 0 < x" + by cooper + +theorem "\(x::int) y. x < y --> 2 * x + 1 < 2 * y" + by cooper + +theorem "\(x::int) y. 2 * x + 1 \ 2 * y" + by cooper + +theorem "\(x::int) y. 0 < x & 0 \ y & 3 * x - 5 * y = 1" + by cooper + +theorem "~ (\(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)" + by cooper + +theorem "~ (\(x::int). False)" + by cooper + +theorem "\(x::int). (2 dvd x) --> (\(y::int). x = 2*y)" + by cooper + +theorem "\(x::int). (2 dvd x) --> (\(y::int). x = 2*y)" + by cooper + +theorem "\(x::int). (2 dvd x) = (\(y::int). x = 2*y)" + by cooper + +theorem "\(x::int). ((2 dvd x) = (\(y::int). x \ 2*y + 1))" + by cooper + +theorem "~ (\(x::int). + ((2 dvd x) = (\(y::int). x \ 2*y+1) | + (\(q::int) (u::int) i. 3*i + 2*q - u < 17) + --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))" + by cooper + +theorem "~ (\(i::int). 4 \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i))" + by cooper + +theorem "\(i::int). 8 \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i)" + by cooper + +theorem "\(j::int). \i. j \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i)" + by cooper + +theorem "~ (\j (i::int). j \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i))" + by cooper + +theorem "(\m::nat. n = 2 * m) --> (n + 1) div 2 = n div 2" + by cooper + +end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/Reflection/MIR.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Reflection/MIR.thy Tue Feb 03 16:50:41 2009 +0100 @@ -0,0 +1,5933 @@ +(* Title: HOL/Reflection/MIR.thy + Author: Amine Chaieb +*) + +theory MIR +imports Complex_Main Efficient_Nat +uses ("mir_tac.ML") +begin + +section {* Quantifier elimination for @{text "\ (0, 1, +, floor, <)"} *} + +declare real_of_int_floor_cancel [simp del] + +primrec alluopairs:: "'a list \ ('a \ 'a) list" where + "alluopairs [] = []" +| "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)" + +lemma alluopairs_set1: "set (alluopairs xs) \ {(x,y). x\ set xs \ y\ set xs}" +by (induct xs, auto) + +lemma alluopairs_set: + "\x\ set xs ; y \ set xs\ \ (x,y) \ set (alluopairs xs) \ (y,x) \ set (alluopairs xs) " +by (induct xs, auto) + +lemma alluopairs_ex: + assumes Pc: "\ x y. P x y = P y x" + shows "(\ x \ set xs. \ y \ set xs. P x y) = (\ (x,y) \ set (alluopairs xs). P x y)" +proof + assume "\x\set xs. \y\set xs. P x y" + then obtain x y where x: "x \ set xs" and y:"y \ set xs" and P: "P x y" by blast + from alluopairs_set[OF x y] P Pc show"\(x, y)\set (alluopairs xs). P x y" + by auto +next + assume "\(x, y)\set (alluopairs xs). P x y" + then obtain "x" and "y" where xy:"(x,y) \ set (alluopairs xs)" and P: "P x y" by blast+ + from xy have "x \ set xs \ y\ set xs" using alluopairs_set1 by blast + with P show "\x\set xs. \y\set xs. P x y" by blast +qed + + (* generate a list from i to j*) +consts iupt :: "int \ int \ int list" +recdef iupt "measure (\ (i,j). nat (j-i +1))" + "iupt (i,j) = (if j (x#xs) ! n = xs ! (n - 1)" +using Nat.gr0_conv_Suc +by clarsimp + + +lemma myl: "\ (a::'a::{pordered_ab_group_add}) (b::'a). (a \ b) = (0 \ b - a)" +proof(clarify) + fix x y ::"'a" + have "(x \ y) = (x - y \ 0)" by (simp only: le_iff_diff_le_0[where a="x" and b="y"]) + also have "\ = (- (y - x) \ 0)" by simp + also have "\ = (0 \ y - x)" by (simp only: neg_le_0_iff_le[where a="y-x"]) + finally show "(x \ y) = (0 \ y - x)" . +qed + +lemma myless: "\ (a::'a::{pordered_ab_group_add}) (b::'a). (a < b) = (0 < b - a)" +proof(clarify) + fix x y ::"'a" + have "(x < y) = (x - y < 0)" by (simp only: less_iff_diff_less_0[where a="x" and b="y"]) + also have "\ = (- (y - x) < 0)" by simp + also have "\ = (0 < y - x)" by (simp only: neg_less_0_iff_less[where a="y-x"]) + finally show "(x < y) = (0 < y - x)" . +qed + +lemma myeq: "\ (a::'a::{pordered_ab_group_add}) (b::'a). (a = b) = (0 = b - a)" + by auto + + (* Maybe should be added to the library \ *) +lemma floor_int_eq: "(real n\ x \ x < real (n+1)) = (floor x = n)" +proof( auto) + assume lb: "real n \ x" + and ub: "x < real n + 1" + have "real (floor x) \ x" by simp + hence "real (floor x) < real (n + 1) " using ub by arith + hence "floor x < n+1" by simp + moreover from lb have "n \ floor x" using floor_mono2[where x="real n" and y="x"] + by simp ultimately show "floor x = n" by simp +qed + +(* Periodicity of dvd *) +lemma dvd_period: + assumes advdd: "(a::int) dvd d" + shows "(a dvd (x + t)) = (a dvd ((x+ c*d) + t))" + using advdd +proof- + {fix x k + from inf_period(3)[OF advdd, rule_format, where x=x and k="-k"] + have " ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))" by simp} + hence "\x.\k. ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))" by simp + then show ?thesis by simp +qed + + (* The Divisibility relation between reals *) +definition + rdvd:: "real \ real \ bool" (infixl "rdvd" 50) +where + rdvd_def: "x rdvd y \ (\k\int. y = x * real k)" + +lemma int_rdvd_real: + shows "real (i::int) rdvd x = (i dvd (floor x) \ real (floor x) = x)" (is "?l = ?r") +proof + assume "?l" + hence th: "\ k. x=real (i*k)" by (simp add: rdvd_def) + hence th': "real (floor x) = x" by (auto simp del: real_of_int_mult) + with th have "\ k. real (floor x) = real (i*k)" by simp + hence "\ k. floor x = i*k" by (simp only: real_of_int_inject) + thus ?r using th' by (simp add: dvd_def) +next + assume "?r" hence "(i\int) dvd \x\real\" .. + hence "\ k. real (floor x) = real (i*k)" + by (simp only: real_of_int_inject) (simp add: dvd_def) + thus ?l using prems by (simp add: rdvd_def) +qed + +lemma int_rdvd_iff: "(real (i::int) rdvd real t) = (i dvd t)" +by (auto simp add: rdvd_def dvd_def) (rule_tac x="k" in exI, simp only :real_of_int_mult[symmetric]) + + +lemma rdvd_abs1: + "(abs (real d) rdvd t) = (real (d ::int) rdvd t)" +proof + assume d: "real d rdvd t" + from d int_rdvd_real have d2: "d dvd (floor t)" and ti: "real (floor t) = t" by auto + + from iffD2[OF zdvd_abs1] d2 have "(abs d) dvd (floor t)" by blast + with ti int_rdvd_real[symmetric] have "real (abs d) rdvd t" by blast + thus "abs (real d) rdvd t" by simp +next + assume "abs (real d) rdvd t" hence "real (abs d) rdvd t" by simp + with int_rdvd_real[where i="abs d" and x="t"] have d2: "abs d dvd floor t" and ti: "real (floor t) =t" by auto + from iffD1[OF zdvd_abs1] d2 have "d dvd floor t" by blast + with ti int_rdvd_real[symmetric] show "real d rdvd t" by blast +qed + +lemma rdvd_minus: "(real (d::int) rdvd t) = (real d rdvd -t)" + apply (auto simp add: rdvd_def) + apply (rule_tac x="-k" in exI, simp) + apply (rule_tac x="-k" in exI, simp) +done + +lemma rdvd_left_0_eq: "(0 rdvd t) = (t=0)" +by (auto simp add: rdvd_def) + +lemma rdvd_mult: + assumes knz: "k\0" + shows "(real (n::int) * real (k::int) rdvd x * real k) = (real n rdvd x)" +using knz by (simp add:rdvd_def) + +lemma rdvd_trans: assumes mn:"m rdvd n" and nk:"n rdvd k" + shows "m rdvd k" +proof- + from rdvd_def mn obtain c where nmc:"n = m * real (c::int)" by auto + from rdvd_def nk obtain c' where nkc:"k = n * real (c'::int)" by auto + hence "k = m * real (c * c')" using nmc by simp + thus ?thesis using rdvd_def by blast +qed + + (*********************************************************************************) + (**** SHADOW SYNTAX AND SEMANTICS ****) + (*********************************************************************************) + +datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num + | Mul int num | Floor num| CF int num num + + (* A size for num to make inductive proofs simpler*) +primrec num_size :: "num \ nat" where + "num_size (C c) = 1" +| "num_size (Bound n) = 1" +| "num_size (Neg a) = 1 + num_size a" +| "num_size (Add a b) = 1 + num_size a + num_size b" +| "num_size (Sub a b) = 3 + num_size a + num_size b" +| "num_size (CN n c a) = 4 + num_size a " +| "num_size (CF c a b) = 4 + num_size a + num_size b" +| "num_size (Mul c a) = 1 + num_size a" +| "num_size (Floor a) = 1 + num_size a" + + (* Semantics of numeral terms (num) *) +primrec Inum :: "real list \ num \ real" where + "Inum bs (C c) = (real c)" +| "Inum bs (Bound n) = bs!n" +| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)" +| "Inum bs (Neg a) = -(Inum bs a)" +| "Inum bs (Add a b) = Inum bs a + Inum bs b" +| "Inum bs (Sub a b) = Inum bs a - Inum bs b" +| "Inum bs (Mul c a) = (real c) * Inum bs a" +| "Inum bs (Floor a) = real (floor (Inum bs a))" +| "Inum bs (CF c a b) = real c * real (floor (Inum bs a)) + Inum bs b" +definition "isint t bs \ real (floor (Inum bs t)) = Inum bs t" + +lemma isint_iff: "isint n bs = (real (floor (Inum bs n)) = Inum bs n)" +by (simp add: isint_def) + +lemma isint_Floor: "isint (Floor n) bs" + by (simp add: isint_iff) + +lemma isint_Mul: "isint e bs \ isint (Mul c e) bs" +proof- + let ?e = "Inum bs e" + let ?fe = "floor ?e" + assume be: "isint e bs" hence efe:"real ?fe = ?e" by (simp add: isint_iff) + have "real ((floor (Inum bs (Mul c e)))) = real (floor (real (c * ?fe)))" using efe by simp + also have "\ = real (c* ?fe)" by (simp only: floor_real_of_int) + also have "\ = real c * ?e" using efe by simp + finally show ?thesis using isint_iff by simp +qed + +lemma isint_neg: "isint e bs \ isint (Neg e) bs" +proof- + let ?I = "\ t. Inum bs t" + assume ie: "isint e bs" + hence th: "real (floor (?I e)) = ?I e" by (simp add: isint_def) + have "real (floor (?I (Neg e))) = real (floor (- (real (floor (?I e)))))" by (simp add: th) + also have "\ = - real (floor (?I e))" by(simp add: floor_minus_real_of_int) + finally show "isint (Neg e) bs" by (simp add: isint_def th) +qed + +lemma isint_sub: + assumes ie: "isint e bs" shows "isint (Sub (C c) e) bs" +proof- + let ?I = "\ t. Inum bs t" + from ie have th: "real (floor (?I e)) = ?I e" by (simp add: isint_def) + have "real (floor (?I (Sub (C c) e))) = real (floor ((real (c -floor (?I e)))))" by (simp add: th) + also have "\ = real (c- floor (?I e))" by(simp add: floor_minus_real_of_int) + finally show "isint (Sub (C c) e) bs" by (simp add: isint_def th) +qed + +lemma isint_add: assumes + ai:"isint a bs" and bi: "isint b bs" shows "isint (Add a b) bs" +proof- + let ?a = "Inum bs a" + let ?b = "Inum bs b" + from ai bi isint_iff have "real (floor (?a + ?b)) = real (floor (real (floor ?a) + real (floor ?b)))" by simp + also have "\ = real (floor ?a) + real (floor ?b)" by simp + also have "\ = ?a + ?b" using ai bi isint_iff by simp + finally show "isint (Add a b) bs" by (simp add: isint_iff) +qed + +lemma isint_c: "isint (C j) bs" + by (simp add: isint_iff) + + + (* FORMULAE *) +datatype fm = + T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num| + NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm + + + (* A size for fm *) +fun fmsize :: "fm \ nat" where + "fmsize (NOT p) = 1 + fmsize p" +| "fmsize (And p q) = 1 + fmsize p + fmsize q" +| "fmsize (Or p q) = 1 + fmsize p + fmsize q" +| "fmsize (Imp p q) = 3 + fmsize p + fmsize q" +| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" +| "fmsize (E p) = 1 + fmsize p" +| "fmsize (A p) = 4+ fmsize p" +| "fmsize (Dvd i t) = 2" +| "fmsize (NDvd i t) = 2" +| "fmsize p = 1" + (* several lemmas about fmsize *) +lemma fmsize_pos: "fmsize p > 0" +by (induct p rule: fmsize.induct) simp_all + + (* Semantics of formulae (fm) *) +primrec Ifm ::"real list \ fm \ bool" where + "Ifm bs T = True" +| "Ifm bs F = False" +| "Ifm bs (Lt a) = (Inum bs a < 0)" +| "Ifm bs (Gt a) = (Inum bs a > 0)" +| "Ifm bs (Le a) = (Inum bs a \ 0)" +| "Ifm bs (Ge a) = (Inum bs a \ 0)" +| "Ifm bs (Eq a) = (Inum bs a = 0)" +| "Ifm bs (NEq a) = (Inum bs a \ 0)" +| "Ifm bs (Dvd i b) = (real i rdvd Inum bs b)" +| "Ifm bs (NDvd i b) = (\(real i rdvd Inum bs b))" +| "Ifm bs (NOT p) = (\ (Ifm bs p))" +| "Ifm bs (And p q) = (Ifm bs p \ Ifm bs q)" +| "Ifm bs (Or p q) = (Ifm bs p \ Ifm bs q)" +| "Ifm bs (Imp p q) = ((Ifm bs p) \ (Ifm bs q))" +| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)" +| "Ifm bs (E p) = (\ x. Ifm (x#bs) p)" +| "Ifm bs (A p) = (\ x. Ifm (x#bs) p)" + +consts prep :: "fm \ fm" +recdef prep "measure fmsize" + "prep (E T) = T" + "prep (E F) = F" + "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))" + "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))" + "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" + "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))" + "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" + "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" + "prep (E p) = E (prep p)" + "prep (A (And p q)) = And (prep (A p)) (prep (A q))" + "prep (A p) = prep (NOT (E (NOT p)))" + "prep (NOT (NOT p)) = prep p" + "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))" + "prep (NOT (A p)) = prep (E (NOT p))" + "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))" + "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))" + "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))" + "prep (NOT p) = NOT (prep p)" + "prep (Or p q) = Or (prep p) (prep q)" + "prep (And p q) = And (prep p) (prep q)" + "prep (Imp p q) = prep (Or (NOT p) q)" + "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))" + "prep p = p" +(hints simp add: fmsize_pos) +lemma prep: "\ bs. Ifm bs (prep p) = Ifm bs p" +by (induct p rule: prep.induct, auto) + + + (* Quantifier freeness *) +fun qfree:: "fm \ bool" where + "qfree (E p) = False" + | "qfree (A p) = False" + | "qfree (NOT p) = qfree p" + | "qfree (And p q) = (qfree p \ qfree q)" + | "qfree (Or p q) = (qfree p \ qfree q)" + | "qfree (Imp p q) = (qfree p \ qfree q)" + | "qfree (Iff p q) = (qfree p \ qfree q)" + | "qfree p = True" + + (* Boundedness and substitution *) +primrec numbound0 :: "num \ bool" (* a num is INDEPENDENT of Bound 0 *) where + "numbound0 (C c) = True" + | "numbound0 (Bound n) = (n>0)" + | "numbound0 (CN n i a) = (n > 0 \ numbound0 a)" + | "numbound0 (Neg a) = numbound0 a" + | "numbound0 (Add a b) = (numbound0 a \ numbound0 b)" + | "numbound0 (Sub a b) = (numbound0 a \ numbound0 b)" + | "numbound0 (Mul i a) = numbound0 a" + | "numbound0 (Floor a) = numbound0 a" + | "numbound0 (CF c a b) = (numbound0 a \ numbound0 b)" + +lemma numbound0_I: + assumes nb: "numbound0 a" + shows "Inum (b#bs) a = Inum (b'#bs) a" + using nb by (induct a) (auto simp add: nth_pos2) + +lemma numbound0_gen: + assumes nb: "numbound0 t" and ti: "isint t (x#bs)" + shows "\ y. isint t (y#bs)" +using nb ti +proof(clarify) + fix y + from numbound0_I[OF nb, where bs="bs" and b="y" and b'="x"] ti[simplified isint_def] + show "isint t (y#bs)" + by (simp add: isint_def) +qed + +primrec bound0:: "fm \ bool" (* A Formula is independent of Bound 0 *) where + "bound0 T = True" + | "bound0 F = True" + | "bound0 (Lt a) = numbound0 a" + | "bound0 (Le a) = numbound0 a" + | "bound0 (Gt a) = numbound0 a" + | "bound0 (Ge a) = numbound0 a" + | "bound0 (Eq a) = numbound0 a" + | "bound0 (NEq a) = numbound0 a" + | "bound0 (Dvd i a) = numbound0 a" + | "bound0 (NDvd i a) = numbound0 a" + | "bound0 (NOT p) = bound0 p" + | "bound0 (And p q) = (bound0 p \ bound0 q)" + | "bound0 (Or p q) = (bound0 p \ bound0 q)" + | "bound0 (Imp p q) = ((bound0 p) \ (bound0 q))" + | "bound0 (Iff p q) = (bound0 p \ bound0 q)" + | "bound0 (E p) = False" + | "bound0 (A p) = False" + +lemma bound0_I: + assumes bp: "bound0 p" + shows "Ifm (b#bs) p = Ifm (b'#bs) p" + using bp numbound0_I [where b="b" and bs="bs" and b'="b'"] + by (induct p) (auto simp add: nth_pos2) + +primrec numsubst0:: "num \ num \ num" (* substitute a num into a num for Bound 0 *) where + "numsubst0 t (C c) = (C c)" + | "numsubst0 t (Bound n) = (if n=0 then t else Bound n)" + | "numsubst0 t (CN n i a) = (if n=0 then Add (Mul i t) (numsubst0 t a) else CN n i (numsubst0 t a))" + | "numsubst0 t (CF i a b) = CF i (numsubst0 t a) (numsubst0 t b)" + | "numsubst0 t (Neg a) = Neg (numsubst0 t a)" + | "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)" + | "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)" + | "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)" + | "numsubst0 t (Floor a) = Floor (numsubst0 t a)" + +lemma numsubst0_I: + shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t" + by (induct t) (simp_all add: nth_pos2) + +lemma numsubst0_I': + assumes nb: "numbound0 a" + shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t" + by (induct t) (simp_all add: nth_pos2 numbound0_I[OF nb, where b="b" and b'="b'"]) + +primrec subst0:: "num \ fm \ fm" (* substitue a num into a formula for Bound 0 *) where + "subst0 t T = T" + | "subst0 t F = F" + | "subst0 t (Lt a) = Lt (numsubst0 t a)" + | "subst0 t (Le a) = Le (numsubst0 t a)" + | "subst0 t (Gt a) = Gt (numsubst0 t a)" + | "subst0 t (Ge a) = Ge (numsubst0 t a)" + | "subst0 t (Eq a) = Eq (numsubst0 t a)" + | "subst0 t (NEq a) = NEq (numsubst0 t a)" + | "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)" + | "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)" + | "subst0 t (NOT p) = NOT (subst0 t p)" + | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)" + | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)" + | "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)" + | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)" + +lemma subst0_I: assumes qfp: "qfree p" + shows "Ifm (b#bs) (subst0 a p) = Ifm ((Inum (b#bs) a)#bs) p" + using qfp numsubst0_I[where b="b" and bs="bs" and a="a"] + by (induct p) (simp_all add: nth_pos2 ) + +consts + decrnum:: "num \ num" + decr :: "fm \ fm" + +recdef decrnum "measure size" + "decrnum (Bound n) = Bound (n - 1)" + "decrnum (Neg a) = Neg (decrnum a)" + "decrnum (Add a b) = Add (decrnum a) (decrnum b)" + "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" + "decrnum (Mul c a) = Mul c (decrnum a)" + "decrnum (Floor a) = Floor (decrnum a)" + "decrnum (CN n c a) = CN (n - 1) c (decrnum a)" + "decrnum (CF c a b) = CF c (decrnum a) (decrnum b)" + "decrnum a = a" + +recdef decr "measure size" + "decr (Lt a) = Lt (decrnum a)" + "decr (Le a) = Le (decrnum a)" + "decr (Gt a) = Gt (decrnum a)" + "decr (Ge a) = Ge (decrnum a)" + "decr (Eq a) = Eq (decrnum a)" + "decr (NEq a) = NEq (decrnum a)" + "decr (Dvd i a) = Dvd i (decrnum a)" + "decr (NDvd i a) = NDvd i (decrnum a)" + "decr (NOT p) = NOT (decr p)" + "decr (And p q) = And (decr p) (decr q)" + "decr (Or p q) = Or (decr p) (decr q)" + "decr (Imp p q) = Imp (decr p) (decr q)" + "decr (Iff p q) = Iff (decr p) (decr q)" + "decr p = p" + +lemma decrnum: assumes nb: "numbound0 t" + shows "Inum (x#bs) t = Inum bs (decrnum t)" + using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2) + +lemma decr: assumes nb: "bound0 p" + shows "Ifm (x#bs) p = Ifm bs (decr p)" + using nb + by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum) + +lemma decr_qf: "bound0 p \ qfree (decr p)" +by (induct p, simp_all) + +consts + isatom :: "fm \ bool" (* test for atomicity *) +recdef isatom "measure size" + "isatom T = True" + "isatom F = True" + "isatom (Lt a) = True" + "isatom (Le a) = True" + "isatom (Gt a) = True" + "isatom (Ge a) = True" + "isatom (Eq a) = True" + "isatom (NEq a) = True" + "isatom (Dvd i b) = True" + "isatom (NDvd i b) = True" + "isatom p = False" + +lemma numsubst0_numbound0: assumes nb: "numbound0 t" + shows "numbound0 (numsubst0 t a)" +using nb by (induct a, auto) + +lemma subst0_bound0: assumes qf: "qfree p" and nb: "numbound0 t" + shows "bound0 (subst0 t p)" +using qf numsubst0_numbound0[OF nb] by (induct p, auto) + +lemma bound0_qf: "bound0 p \ qfree p" +by (induct p, simp_all) + + +definition djf:: "('a \ fm) \ 'a \ fm \ fm" where + "djf f p q = (if q=T then T else if q=F then f p else + (let fp = f p in case fp of T \ T | F \ q | _ \ Or fp q))" + +definition evaldjf:: "('a \ fm) \ 'a list \ fm" where + "evaldjf f ps = foldr (djf f) ps F" + +lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)" +by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) +(cases "f p", simp_all add: Let_def djf_def) + +lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\ p \ set ps. Ifm bs (f p))" + by(induct ps, simp_all add: evaldjf_def djf_Or) + +lemma evaldjf_bound0: + assumes nb: "\ x\ set xs. bound0 (f x)" + shows "bound0 (evaldjf f xs)" + using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) + +lemma evaldjf_qf: + assumes nb: "\ x\ set xs. qfree (f x)" + shows "qfree (evaldjf f xs)" + using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) + +consts + disjuncts :: "fm \ fm list" + conjuncts :: "fm \ fm list" +recdef disjuncts "measure size" + "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)" + "disjuncts F = []" + "disjuncts p = [p]" + +recdef conjuncts "measure size" + "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)" + "conjuncts T = []" + "conjuncts p = [p]" +lemma disjuncts: "(\ q\ set (disjuncts p). Ifm bs q) = Ifm bs p" +by(induct p rule: disjuncts.induct, auto) +lemma conjuncts: "(\ q\ set (conjuncts p). Ifm bs q) = Ifm bs p" +by(induct p rule: conjuncts.induct, auto) + +lemma disjuncts_nb: "bound0 p \ \ q\ set (disjuncts p). bound0 q" +proof- + assume nb: "bound0 p" + hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto) + thus ?thesis by (simp only: list_all_iff) +qed +lemma conjuncts_nb: "bound0 p \ \ q\ set (conjuncts p). bound0 q" +proof- + assume nb: "bound0 p" + hence "list_all bound0 (conjuncts p)" by (induct p rule:conjuncts.induct,auto) + thus ?thesis by (simp only: list_all_iff) +qed + +lemma disjuncts_qf: "qfree p \ \ q\ set (disjuncts p). qfree q" +proof- + assume qf: "qfree p" + hence "list_all qfree (disjuncts p)" + by (induct p rule: disjuncts.induct, auto) + thus ?thesis by (simp only: list_all_iff) +qed +lemma conjuncts_qf: "qfree p \ \ q\ set (conjuncts p). qfree q" +proof- + assume qf: "qfree p" + hence "list_all qfree (conjuncts p)" + by (induct p rule: conjuncts.induct, auto) + thus ?thesis by (simp only: list_all_iff) +qed + +constdefs DJ :: "(fm \ fm) \ fm \ fm" + "DJ f p \ evaldjf f (disjuncts p)" + +lemma DJ: assumes fdj: "\ p q. f (Or p q) = Or (f p) (f q)" + and fF: "f F = F" + shows "Ifm bs (DJ f p) = Ifm bs (f p)" +proof- + have "Ifm bs (DJ f p) = (\ q \ set (disjuncts p). Ifm bs (f q))" + by (simp add: DJ_def evaldjf_ex) + also have "\ = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto) + finally show ?thesis . +qed + +lemma DJ_qf: assumes + fqf: "\ p. qfree p \ qfree (f p)" + shows "\p. qfree p \ qfree (DJ f p) " +proof(clarify) + fix p assume qf: "qfree p" + have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def) + from disjuncts_qf[OF qf] have "\ q\ set (disjuncts p). qfree q" . + with fqf have th':"\ q\ set (disjuncts p). qfree (f q)" by blast + + from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp +qed + +lemma DJ_qe: assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" + shows "\ bs p. qfree p \ qfree (DJ qe p) \ (Ifm bs ((DJ qe p)) = Ifm bs (E p))" +proof(clarify) + fix p::fm and bs + assume qf: "qfree p" + from qe have qth: "\ p. qfree p \ qfree (qe p)" by blast + from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto + have "Ifm bs (DJ qe p) = (\ q\ set (disjuncts p). Ifm bs (qe q))" + by (simp add: DJ_def evaldjf_ex) + also have "\ = (\ q \ set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto + also have "\ = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto) + finally show "qfree (DJ qe p) \ Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast +qed + (* Simplification *) + + (* Algebraic simplifications for nums *) +consts bnds:: "num \ nat list" + lex_ns:: "nat list \ nat list \ bool" +recdef bnds "measure size" + "bnds (Bound n) = [n]" + "bnds (CN n c a) = n#(bnds a)" + "bnds (Neg a) = bnds a" + "bnds (Add a b) = (bnds a)@(bnds b)" + "bnds (Sub a b) = (bnds a)@(bnds b)" + "bnds (Mul i a) = bnds a" + "bnds (Floor a) = bnds a" + "bnds (CF c a b) = (bnds a)@(bnds b)" + "bnds a = []" +recdef lex_ns "measure (\ (xs,ys). length xs + length ys)" + "lex_ns ([], ms) = True" + "lex_ns (ns, []) = False" + "lex_ns (n#ns, m#ms) = (n ((n = m) \ lex_ns (ns,ms))) " +constdefs lex_bnd :: "num \ num \ bool" + "lex_bnd t s \ lex_ns (bnds t, bnds s)" + +consts + numgcdh:: "num \ int \ int" + reducecoeffh:: "num \ int \ num" + dvdnumcoeff:: "num \ int \ bool" +consts maxcoeff:: "num \ int" +recdef maxcoeff "measure size" + "maxcoeff (C i) = abs i" + "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)" + "maxcoeff (CF c t s) = max (abs c) (maxcoeff s)" + "maxcoeff t = 1" + +lemma maxcoeff_pos: "maxcoeff t \ 0" + apply (induct t rule: maxcoeff.induct, auto) + done + +recdef numgcdh "measure size" + "numgcdh (C i) = (\g. zgcd i g)" + "numgcdh (CN n c t) = (\g. zgcd c (numgcdh t g))" + "numgcdh (CF c s t) = (\g. zgcd c (numgcdh t g))" + "numgcdh t = (\g. 1)" + +definition + numgcd :: "num \ int" +where + numgcd_def: "numgcd t = numgcdh t (maxcoeff t)" + +recdef reducecoeffh "measure size" + "reducecoeffh (C i) = (\ g. C (i div g))" + "reducecoeffh (CN n c t) = (\ g. CN n (c div g) (reducecoeffh t g))" + "reducecoeffh (CF c s t) = (\ g. CF (c div g) s (reducecoeffh t g))" + "reducecoeffh t = (\g. t)" + +definition + reducecoeff :: "num \ num" +where + reducecoeff_def: "reducecoeff t = + (let g = numgcd t in + if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)" + +recdef dvdnumcoeff "measure size" + "dvdnumcoeff (C i) = (\ g. g dvd i)" + "dvdnumcoeff (CN n c t) = (\ g. g dvd c \ (dvdnumcoeff t g))" + "dvdnumcoeff (CF c s t) = (\ g. g dvd c \ (dvdnumcoeff t g))" + "dvdnumcoeff t = (\g. False)" + +lemma dvdnumcoeff_trans: + assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'" + shows "dvdnumcoeff t g" + using dgt' gdg + by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg zdvd_trans[OF gdg]) + +declare zdvd_trans [trans add] + +lemma natabs0: "(nat (abs x) = 0) = (x = 0)" +by arith + +lemma numgcd0: + assumes g0: "numgcd t = 0" + shows "Inum bs t = 0" +proof- + have "\x. numgcdh t x= 0 \ Inum bs t = 0" + by (induct t rule: numgcdh.induct, auto simp add: zgcd_def gcd_zero natabs0 max_def maxcoeff_pos) + thus ?thesis using g0[simplified numgcd_def] by blast +qed + +lemma numgcdh_pos: assumes gp: "g \ 0" shows "numgcdh t g \ 0" + using gp + by (induct t rule: numgcdh.induct, auto simp add: zgcd_def) + +lemma numgcd_pos: "numgcd t \0" + by (simp add: numgcd_def numgcdh_pos maxcoeff_pos) + +lemma reducecoeffh: + assumes gt: "dvdnumcoeff t g" and gp: "g > 0" + shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t" + using gt +proof(induct t rule: reducecoeffh.induct) + case (1 i) hence gd: "g dvd i" by simp + from gp have gnz: "g \ 0" by simp + from prems show ?case by (simp add: real_of_int_div[OF gnz gd]) +next + case (2 n c t) hence gd: "g dvd c" by simp + from gp have gnz: "g \ 0" by simp + from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps) +next + case (3 c s t) hence gd: "g dvd c" by simp + from gp have gnz: "g \ 0" by simp + from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps) +qed (auto simp add: numgcd_def gp) +consts ismaxcoeff:: "num \ int \ bool" +recdef ismaxcoeff "measure size" + "ismaxcoeff (C i) = (\ x. abs i \ x)" + "ismaxcoeff (CN n c t) = (\x. abs c \ x \ (ismaxcoeff t x))" + "ismaxcoeff (CF c s t) = (\x. abs c \ x \ (ismaxcoeff t x))" + "ismaxcoeff t = (\x. True)" + +lemma ismaxcoeff_mono: "ismaxcoeff t c \ c \ c' \ ismaxcoeff t c'" +by (induct t rule: ismaxcoeff.induct, auto) + +lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" +proof (induct t rule: maxcoeff.induct) + case (2 n c t) + hence H:"ismaxcoeff t (maxcoeff t)" . + have thh: "maxcoeff t \ max (abs c) (maxcoeff t)" by (simp add: le_maxI2) + from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1) +next + case (3 c t s) + hence H1:"ismaxcoeff s (maxcoeff s)" by auto + have thh1: "maxcoeff s \ max \c\ (maxcoeff s)" by (simp add: max_def) + from ismaxcoeff_mono[OF H1 thh1] show ?case by (simp add: le_maxI1) +qed simp_all + +lemma zgcd_gt1: "zgcd i j > 1 \ ((abs i > 1 \ abs j > 1) \ (abs i = 0 \ abs j > 1) \ (abs i > 1 \ abs j = 0))" + apply (unfold zgcd_def) + apply (cases "i = 0", simp_all) + apply (cases "j = 0", simp_all) + apply (cases "abs i = 1", simp_all) + apply (cases "abs j = 1", simp_all) + apply auto + done +lemma numgcdh0:"numgcdh t m = 0 \ m =0" + by (induct t rule: numgcdh.induct, auto simp add:zgcd0) + +lemma dvdnumcoeff_aux: + assumes "ismaxcoeff t m" and mp:"m \ 0" and "numgcdh t m > 1" + shows "dvdnumcoeff t (numgcdh t m)" +using prems +proof(induct t rule: numgcdh.induct) + case (2 n c t) + let ?g = "numgcdh t m" + from prems have th:"zgcd c ?g > 1" by simp + from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] + have "(abs c > 1 \ ?g > 1) \ (abs c = 0 \ ?g > 1) \ (abs c > 1 \ ?g = 0)" by simp + moreover {assume "abs c > 1" and gp: "?g > 1" with prems + have th: "dvdnumcoeff t ?g" by simp + have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) + from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)} + moreover {assume "abs c = 0 \ ?g > 1" + with prems have th: "dvdnumcoeff t ?g" by simp + have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) + from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1) + hence ?case by simp } + moreover {assume "abs c > 1" and g0:"?g = 0" + from numgcdh0[OF g0] have "m=0". with prems have ?case by simp } + ultimately show ?case by blast +next + case (3 c s t) + let ?g = "numgcdh t m" + from prems have th:"zgcd c ?g > 1" by simp + from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] + have "(abs c > 1 \ ?g > 1) \ (abs c = 0 \ ?g > 1) \ (abs c > 1 \ ?g = 0)" by simp + moreover {assume "abs c > 1" and gp: "?g > 1" with prems + have th: "dvdnumcoeff t ?g" by simp + have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) + from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)} + moreover {assume "abs c = 0 \ ?g > 1" + with prems have th: "dvdnumcoeff t ?g" by simp + have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) + from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1) + hence ?case by simp } + moreover {assume "abs c > 1" and g0:"?g = 0" + from numgcdh0[OF g0] have "m=0". with prems have ?case by simp } + ultimately show ?case by blast +qed(auto simp add: zgcd_zdvd1) + +lemma dvdnumcoeff_aux2: + assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \ numgcd t > 0" + using prems +proof (simp add: numgcd_def) + let ?mc = "maxcoeff t" + let ?g = "numgcdh t ?mc" + have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff) + have th2: "?mc \ 0" by (rule maxcoeff_pos) + assume H: "numgcdh t ?mc > 1" + from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" . +qed + +lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t" +proof- + let ?g = "numgcd t" + have "?g \ 0" by (simp add: numgcd_pos) + hence "?g = 0 \ ?g = 1 \ ?g > 1" by auto + moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} + moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} + moreover { assume g1:"?g > 1" + from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+ + from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis + by (simp add: reducecoeff_def Let_def)} + ultimately show ?thesis by blast +qed + +lemma reducecoeffh_numbound0: "numbound0 t \ numbound0 (reducecoeffh t g)" +by (induct t rule: reducecoeffh.induct, auto) + +lemma reducecoeff_numbound0: "numbound0 t \ numbound0 (reducecoeff t)" +using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def) + +consts + simpnum:: "num \ num" + numadd:: "num \ num \ num" + nummul:: "num \ int \ num" + +recdef numadd "measure (\ (t,s). size t + size s)" + "numadd (CN n1 c1 r1,CN n2 c2 r2) = + (if n1=n2 then + (let c = c1 + c2 + in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2)))) + else if n1 \ n2 then CN n1 c1 (numadd (r1,CN n2 c2 r2)) + else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))" + "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))" + "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" + "numadd (CF c1 t1 r1,CF c2 t2 r2) = + (if t1 = t2 then + (let c=c1+c2; s= numadd(r1,r2) in (if c=0 then s else CF c t1 s)) + else if lex_bnd t1 t2 then CF c1 t1 (numadd(r1,CF c2 t2 r2)) + else CF c2 t2 (numadd(CF c1 t1 r1,r2)))" + "numadd (CF c1 t1 r1,C c) = CF c1 t1 (numadd (r1, C c))" + "numadd (C c,CF c1 t1 r1) = CF c1 t1 (numadd (r1, C c))" + "numadd (C b1, C b2) = C (b1+b2)" + "numadd (a,b) = Add a b" + +lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" +apply (induct t s rule: numadd.induct, simp_all add: Let_def) + apply (case_tac "c1+c2 = 0",case_tac "n1 \ n2", simp_all) + apply (case_tac "n1 = n2", simp_all add: algebra_simps) + apply (simp only: left_distrib[symmetric]) + apply simp +apply (case_tac "lex_bnd t1 t2", simp_all) + apply (case_tac "c1+c2 = 0") + by (case_tac "t1 = t2", simp_all add: algebra_simps left_distrib[symmetric] real_of_int_mult[symmetric] real_of_int_add[symmetric]del: real_of_int_mult real_of_int_add left_distrib) + +lemma numadd_nb[simp]: "\ numbound0 t ; numbound0 s\ \ numbound0 (numadd (t,s))" +by (induct t s rule: numadd.induct, auto simp add: Let_def) + +recdef nummul "measure size" + "nummul (C j) = (\ i. C (i*j))" + "nummul (CN n c t) = (\ i. CN n (c*i) (nummul t i))" + "nummul (CF c t s) = (\ i. CF (c*i) t (nummul s i))" + "nummul (Mul c t) = (\ i. nummul t (i*c))" + "nummul t = (\ i. Mul i t)" + +lemma nummul[simp]: "\ i. Inum bs (nummul t i) = Inum bs (Mul i t)" +by (induct t rule: nummul.induct, auto simp add: algebra_simps) + +lemma nummul_nb[simp]: "\ i. numbound0 t \ numbound0 (nummul t i)" +by (induct t rule: nummul.induct, auto) + +constdefs numneg :: "num \ num" + "numneg t \ nummul t (- 1)" + +constdefs numsub :: "num \ num \ num" + "numsub s t \ (if s = t then C 0 else numadd (s,numneg t))" + +lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)" +using numneg_def nummul by simp + +lemma numneg_nb[simp]: "numbound0 t \ numbound0 (numneg t)" +using numneg_def by simp + +lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)" +using numsub_def by simp + +lemma numsub_nb[simp]: "\ numbound0 t ; numbound0 s\ \ numbound0 (numsub t s)" +using numsub_def by simp + +lemma isint_CF: assumes si: "isint s bs" shows "isint (CF c t s) bs" +proof- + have cti: "isint (Mul c (Floor t)) bs" by (simp add: isint_Mul isint_Floor) + + have "?thesis = isint (Add (Mul c (Floor t)) s) bs" by (simp add: isint_def) + also have "\" by (simp add: isint_add cti si) + finally show ?thesis . +qed + +consts split_int:: "num \ num\num" +recdef split_int "measure num_size" + "split_int (C c) = (C 0, C c)" + "split_int (CN n c b) = + (let (bv,bi) = split_int b + in (CN n c bv, bi))" + "split_int (CF c a b) = + (let (bv,bi) = split_int b + in (bv, CF c a bi))" + "split_int a = (a,C 0)" + +lemma split_int:"\ tv ti. split_int t = (tv,ti) \ (Inum bs (Add tv ti) = Inum bs t) \ isint ti bs" +proof (induct t rule: split_int.induct) + case (2 c n b tv ti) + let ?bv = "fst (split_int b)" + let ?bi = "snd (split_int b)" + have "split_int b = (?bv,?bi)" by simp + with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+ + from prems(2) have tibi: "ti = ?bi" by (simp add: Let_def split_def) + from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def) +next + case (3 c a b tv ti) + let ?bv = "fst (split_int b)" + let ?bi = "snd (split_int b)" + have "split_int b = (?bv,?bi)" by simp + with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+ + from prems(2) have tibi: "ti = CF c a ?bi" by (simp add: Let_def split_def) + from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def isint_Floor isint_add isint_Mul isint_CF) +qed (auto simp add: Let_def isint_iff isint_Floor isint_add isint_Mul split_def algebra_simps) + +lemma split_int_nb: "numbound0 t \ numbound0 (fst (split_int t)) \ numbound0 (snd (split_int t)) " +by (induct t rule: split_int.induct, auto simp add: Let_def split_def) + +definition + numfloor:: "num \ num" +where + numfloor_def: "numfloor t = (let (tv,ti) = split_int t in + (case tv of C i \ numadd (tv,ti) + | _ \ numadd(CF 1 tv (C 0),ti)))" + +lemma numfloor[simp]: "Inum bs (numfloor t) = Inum bs (Floor t)" (is "?n t = ?N (Floor t)") +proof- + let ?tv = "fst (split_int t)" + let ?ti = "snd (split_int t)" + have tvti:"split_int t = (?tv,?ti)" by simp + {assume H: "\ v. ?tv \ C v" + hence th1: "?n t = ?N (Add (Floor ?tv) ?ti)" + by (cases ?tv, auto simp add: numfloor_def Let_def split_def numadd) + from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+ + hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp + also have "\ = real (floor (?N ?tv) + (floor (?N ?ti)))" + by (simp,subst tii[simplified isint_iff, symmetric]) simp + also have "\ = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff]) + finally have ?thesis using th1 by simp} + moreover {fix v assume H:"?tv = C v" + from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+ + hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp + also have "\ = real (floor (?N ?tv) + (floor (?N ?ti)))" + by (simp,subst tii[simplified isint_iff, symmetric]) simp + also have "\ = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff]) + finally have ?thesis by (simp add: H numfloor_def Let_def split_def numadd) } + ultimately show ?thesis by auto +qed + +lemma numfloor_nb[simp]: "numbound0 t \ numbound0 (numfloor t)" + using split_int_nb[where t="t"] + by (cases "fst(split_int t)" , auto simp add: numfloor_def Let_def split_def numadd_nb) + +recdef simpnum "measure num_size" + "simpnum (C j) = C j" + "simpnum (Bound n) = CN n 1 (C 0)" + "simpnum (Neg t) = numneg (simpnum t)" + "simpnum (Add t s) = numadd (simpnum t,simpnum s)" + "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" + "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)" + "simpnum (Floor t) = numfloor (simpnum t)" + "simpnum (CN n c t) = (if c=0 then simpnum t else CN n c (simpnum t))" + "simpnum (CF c t s) = simpnum(Add (Mul c (Floor t)) s)" + +lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t" +by (induct t rule: simpnum.induct, auto) + +lemma simpnum_numbound0[simp]: + "numbound0 t \ numbound0 (simpnum t)" +by (induct t rule: simpnum.induct, auto) + +consts nozerocoeff:: "num \ bool" +recdef nozerocoeff "measure size" + "nozerocoeff (C c) = True" + "nozerocoeff (CN n c t) = (c\0 \ nozerocoeff t)" + "nozerocoeff (CF c s t) = (c \ 0 \ nozerocoeff t)" + "nozerocoeff (Mul c t) = (c\0 \ nozerocoeff t)" + "nozerocoeff t = True" + +lemma numadd_nz : "nozerocoeff a \ nozerocoeff b \ nozerocoeff (numadd (a,b))" +by (induct a b rule: numadd.induct,auto simp add: Let_def) + +lemma nummul_nz : "\ i. i\0 \ nozerocoeff a \ nozerocoeff (nummul a i)" + by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz) + +lemma numneg_nz : "nozerocoeff a \ nozerocoeff (numneg a)" +by (simp add: numneg_def nummul_nz) + +lemma numsub_nz: "nozerocoeff a \ nozerocoeff b \ nozerocoeff (numsub a b)" +by (simp add: numsub_def numneg_nz numadd_nz) + +lemma split_int_nz: "nozerocoeff t \ nozerocoeff (fst (split_int t)) \ nozerocoeff (snd (split_int t))" +by (induct t rule: split_int.induct,auto simp add: Let_def split_def) + +lemma numfloor_nz: "nozerocoeff t \ nozerocoeff (numfloor t)" +by (simp add: numfloor_def Let_def split_def) +(cases "fst (split_int t)", simp_all add: split_int_nz numadd_nz) + +lemma simpnum_nz: "nozerocoeff (simpnum t)" +by(induct t rule: simpnum.induct, auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz numfloor_nz) + +lemma maxcoeff_nz: "nozerocoeff t \ maxcoeff t = 0 \ t = C 0" +proof (induct t rule: maxcoeff.induct) + case (2 n c t) + hence cnz: "c \0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+ + have "max (abs c) (maxcoeff t) \ abs c" by (simp add: le_maxI1) + with cnz have "max (abs c) (maxcoeff t) > 0" by arith + with prems show ?case by simp +next + case (3 c s t) + hence cnz: "c \0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+ + have "max (abs c) (maxcoeff t) \ abs c" by (simp add: le_maxI1) + with cnz have "max (abs c) (maxcoeff t) > 0" by arith + with prems show ?case by simp +qed auto + +lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0" +proof- + from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def) + from numgcdh0[OF th] have th:"maxcoeff t = 0" . + from maxcoeff_nz[OF nz th] show ?thesis . +qed + +constdefs simp_num_pair:: "(num \ int) \ num \ int" + "simp_num_pair \ (\ (t,n). (if n = 0 then (C 0, 0) else + (let t' = simpnum t ; g = numgcd t' in + if g > 1 then (let g' = zgcd n g in + if g' = 1 then (t',n) + else (reducecoeffh t' g', n div g')) + else (t',n))))" + +lemma simp_num_pair_ci: + shows "((\ (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\ (t,n). Inum bs t / real n) (t,n))" + (is "?lhs = ?rhs") +proof- + let ?t' = "simpnum t" + let ?g = "numgcd ?t'" + let ?g' = "zgcd n ?g" + {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)} + moreover + { assume nnz: "n \ 0" + {assume "\ ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def)} + moreover + {assume g1:"?g>1" hence g0: "?g > 0" by simp + from zgcd0 g1 nnz have gp0: "?g' \ 0" by simp + hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith + hence "?g'= 1 \ ?g' > 1" by arith + moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)} + moreover {assume g'1:"?g'>1" + from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" .. + let ?tt = "reducecoeffh ?t' ?g'" + let ?t = "Inum bs ?tt" + have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) + have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) + have gpdgp: "?g' dvd ?g'" by simp + from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] + have th2:"real ?g' * ?t = Inum bs ?t'" by simp + from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def) + also have "\ = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp + also have "\ = (Inum bs ?t' / real n)" + using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp + finally have "?lhs = Inum bs t / real n" by simp + then have ?thesis using prems by (simp add: simp_num_pair_def)} + ultimately have ?thesis by blast} + ultimately have ?thesis by blast} + ultimately show ?thesis by blast +qed + +lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')" + shows "numbound0 t' \ n' >0" +proof- + let ?t' = "simpnum t" + let ?g = "numgcd ?t'" + let ?g' = "zgcd n ?g" + {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)} + moreover + { assume nnz: "n \ 0" + {assume "\ ?g > 1" hence ?thesis using prems by (auto simp add: Let_def simp_num_pair_def)} + moreover + {assume g1:"?g>1" hence g0: "?g > 0" by simp + from zgcd0 g1 nnz have gp0: "?g' \ 0" by simp + hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith + hence "?g'= 1 \ ?g' > 1" by arith + moreover {assume "?g'=1" hence ?thesis using prems + by (auto simp add: Let_def simp_num_pair_def)} + moreover {assume g'1:"?g'>1" + have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) + have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) + have gpdgp: "?g' dvd ?g'" by simp + from zdvd_imp_le[OF gpdd np] have g'n: "?g' \ n" . + from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]] + have "n div ?g' >0" by simp + hence ?thesis using prems + by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0)} + ultimately have ?thesis by blast} + ultimately have ?thesis by blast} + ultimately show ?thesis by blast +qed + +consts not:: "fm \ fm" +recdef not "measure size" + "not (NOT p) = p" + "not T = F" + "not F = T" + "not (Lt t) = Ge t" + "not (Le t) = Gt t" + "not (Gt t) = Le t" + "not (Ge t) = Lt t" + "not (Eq t) = NEq t" + "not (NEq t) = Eq t" + "not (Dvd i t) = NDvd i t" + "not (NDvd i t) = Dvd i t" + "not (And p q) = Or (not p) (not q)" + "not (Or p q) = And (not p) (not q)" + "not p = NOT p" +lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)" +by (induct p) auto +lemma not_qf[simp]: "qfree p \ qfree (not p)" +by (induct p, auto) +lemma not_nb[simp]: "bound0 p \ bound0 (not p)" +by (induct p, auto) + +constdefs conj :: "fm \ fm \ fm" + "conj p q \ (if (p = F \ q=F) then F else if p=T then q else if q=T then p else + if p = q then p else And p q)" +lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)" +by (cases "p=F \ q=F",simp_all add: conj_def) (cases p,simp_all) + +lemma conj_qf[simp]: "\qfree p ; qfree q\ \ qfree (conj p q)" +using conj_def by auto +lemma conj_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (conj p q)" +using conj_def by auto + +constdefs disj :: "fm \ fm \ fm" + "disj p q \ (if (p = T \ q=T) then T else if p=F then q else if q=F then p + else if p=q then p else Or p q)" + +lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)" +by (cases "p=T \ q=T",simp_all add: disj_def) (cases p,simp_all) +lemma disj_qf[simp]: "\qfree p ; qfree q\ \ qfree (disj p q)" +using disj_def by auto +lemma disj_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (disj p q)" +using disj_def by auto + +constdefs imp :: "fm \ fm \ fm" + "imp p q \ (if (p = F \ q=T \ p=q) then T else if p=T then q else if q=F then not p + else Imp p q)" +lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)" +by (cases "p=F \ q=T",simp_all add: imp_def) +lemma imp_qf[simp]: "\qfree p ; qfree q\ \ qfree (imp p q)" +using imp_def by (cases "p=F \ q=T",simp_all add: imp_def) +lemma imp_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (imp p q)" +using imp_def by (cases "p=F \ q=T \ p=q",simp_all add: imp_def) + +constdefs iff :: "fm \ fm \ fm" + "iff p q \ (if (p = q) then T else if (p = not q \ not p = q) then F else + if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else + Iff p q)" +lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)" + by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp add:not) +(cases "not p= q", auto simp add:not) +lemma iff_qf[simp]: "\qfree p ; qfree q\ \ qfree (iff p q)" + by (unfold iff_def,cases "p=q", auto) +lemma iff_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (iff p q)" +using iff_def by (unfold iff_def,cases "p=q", auto) + +consts check_int:: "num \ bool" +recdef check_int "measure size" + "check_int (C i) = True" + "check_int (Floor t) = True" + "check_int (Mul i t) = check_int t" + "check_int (Add t s) = (check_int t \ check_int s)" + "check_int (Neg t) = check_int t" + "check_int (CF c t s) = check_int s" + "check_int t = False" +lemma check_int: "check_int t \ isint t bs" +by (induct t, auto simp add: isint_add isint_Floor isint_Mul isint_neg isint_c isint_CF) + +lemma rdvd_left1_int: "real \t\ = t \ 1 rdvd t" + by (simp add: rdvd_def,rule_tac x="\t\" in exI) simp + +lemma rdvd_reduce: + assumes gd:"g dvd d" and gc:"g dvd c" and gp: "g > 0" + shows "real (d::int) rdvd real (c::int)*t = (real (d div g) rdvd real (c div g)*t)" +proof + assume d: "real d rdvd real c * t" + from d rdvd_def obtain k where k_def: "real c * t = real d* real (k::int)" by auto + from gd dvd_def obtain kd where kd_def: "d = g * kd" by auto + from gc dvd_def obtain kc where kc_def: "c = g * kc" by auto + from k_def kd_def kc_def have "real g * real kc * t = real g * real kd * real k" by simp + hence "real kc * t = real kd * real k" using gp by simp + hence th:"real kd rdvd real kc * t" using rdvd_def by blast + from kd_def gp have th':"kd = d div g" by simp + from kc_def gp have "kc = c div g" by simp + with th th' show "real (d div g) rdvd real (c div g) * t" by simp +next + assume d: "real (d div g) rdvd real (c div g) * t" + from gp have gnz: "g \ 0" by simp + thus "real d rdvd real c * t" using d rdvd_mult[OF gnz, where n="d div g" and x="real (c div g) * t"] real_of_int_div[OF gnz gd] real_of_int_div[OF gnz gc] by simp +qed + +constdefs simpdvd:: "int \ num \ (int \ num)" + "simpdvd d t \ + (let g = numgcd t in + if g > 1 then (let g' = zgcd d g in + if g' = 1 then (d, t) + else (d div g',reducecoeffh t g')) + else (d, t))" +lemma simpdvd: + assumes tnz: "nozerocoeff t" and dnz: "d \ 0" + shows "Ifm bs (Dvd (fst (simpdvd d t)) (snd (simpdvd d t))) = Ifm bs (Dvd d t)" +proof- + let ?g = "numgcd t" + let ?g' = "zgcd d ?g" + {assume "\ ?g > 1" hence ?thesis by (simp add: Let_def simpdvd_def)} + moreover + {assume g1:"?g>1" hence g0: "?g > 0" by simp + from zgcd0 g1 dnz have gp0: "?g' \ 0" by simp + hence g'p: "?g' > 0" using zgcd_pos[where i="d" and j="numgcd t"] by arith + hence "?g'= 1 \ ?g' > 1" by arith + moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simpdvd_def)} + moreover {assume g'1:"?g'>1" + from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" .. + let ?tt = "reducecoeffh t ?g'" + let ?t = "Inum bs ?tt" + have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) + have gpdd: "?g' dvd d" by (simp add: zgcd_zdvd1) + have gpdgp: "?g' dvd ?g'" by simp + from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] + have th2:"real ?g' * ?t = Inum bs t" by simp + from prems have "Ifm bs (Dvd (fst (simpdvd d t)) (snd(simpdvd d t))) = Ifm bs (Dvd (d div ?g') ?tt)" + by (simp add: simpdvd_def Let_def) + also have "\ = (real d rdvd (Inum bs t))" + using rdvd_reduce[OF gpdd gpdgp g'p, where t="?t", simplified zdiv_self[OF gp0]] + th2[symmetric] by simp + finally have ?thesis by simp } + ultimately have ?thesis by blast + } + ultimately show ?thesis by blast +qed + +consts simpfm :: "fm \ fm" +recdef simpfm "measure fmsize" + "simpfm (And p q) = conj (simpfm p) (simpfm q)" + "simpfm (Or p q) = disj (simpfm p) (simpfm q)" + "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" + "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" + "simpfm (NOT p) = not (simpfm p)" + "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \ if (v < 0) then T else F + | _ \ Lt (reducecoeff a'))" + "simpfm (Le a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Le (reducecoeff a'))" + "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \ if (v > 0) then T else F | _ \ Gt (reducecoeff a'))" + "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Ge (reducecoeff a'))" + "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \ if (v = 0) then T else F | _ \ Eq (reducecoeff a'))" + "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ NEq (reducecoeff a'))" + "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a) + else if (abs i = 1) \ check_int a then T + else let a' = simpnum a in case a' of C v \ if (i dvd v) then T else F | _ \ (let (d,t) = simpdvd i a' in Dvd d t))" + "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a) + else if (abs i = 1) \ check_int a then F + else let a' = simpnum a in case a' of C v \ if (\(i dvd v)) then T else F | _ \ (let (d,t) = simpdvd i a' in NDvd d t))" + "simpfm p = p" + +lemma simpfm[simp]: "Ifm bs (simpfm p) = Ifm bs p" +proof(induct p rule: simpfm.induct) + case (6 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume H:"\ (\ v. ?sa = C v)" + let ?g = "numgcd ?sa" + let ?rsa = "reducecoeff ?sa" + let ?r = "Inum bs ?rsa" + have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) + {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} + with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) + hence gp: "real ?g > 0" by simp + have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) + with sa have "Inum bs a < 0 = (real ?g * ?r < real ?g * 0)" by simp + also have "\ = (?r < 0)" using gp + by (simp only: mult_less_cancel_left) simp + finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} + ultimately show ?case by blast +next + case (7 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume H:"\ (\ v. ?sa = C v)" + let ?g = "numgcd ?sa" + let ?rsa = "reducecoeff ?sa" + let ?r = "Inum bs ?rsa" + have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) + {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} + with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) + hence gp: "real ?g > 0" by simp + have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) + with sa have "Inum bs a \ 0 = (real ?g * ?r \ real ?g * 0)" by simp + also have "\ = (?r \ 0)" using gp + by (simp only: mult_le_cancel_left) simp + finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} + ultimately show ?case by blast +next + case (8 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume H:"\ (\ v. ?sa = C v)" + let ?g = "numgcd ?sa" + let ?rsa = "reducecoeff ?sa" + let ?r = "Inum bs ?rsa" + have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) + {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} + with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) + hence gp: "real ?g > 0" by simp + have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) + with sa have "Inum bs a > 0 = (real ?g * ?r > real ?g * 0)" by simp + also have "\ = (?r > 0)" using gp + by (simp only: mult_less_cancel_left) simp + finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} + ultimately show ?case by blast +next + case (9 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume H:"\ (\ v. ?sa = C v)" + let ?g = "numgcd ?sa" + let ?rsa = "reducecoeff ?sa" + let ?r = "Inum bs ?rsa" + have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) + {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} + with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) + hence gp: "real ?g > 0" by simp + have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) + with sa have "Inum bs a \ 0 = (real ?g * ?r \ real ?g * 0)" by simp + also have "\ = (?r \ 0)" using gp + by (simp only: mult_le_cancel_left) simp + finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} + ultimately show ?case by blast +next + case (10 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume H:"\ (\ v. ?sa = C v)" + let ?g = "numgcd ?sa" + let ?rsa = "reducecoeff ?sa" + let ?r = "Inum bs ?rsa" + have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) + {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} + with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) + hence gp: "real ?g > 0" by simp + have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) + with sa have "Inum bs a = 0 = (real ?g * ?r = 0)" by simp + also have "\ = (?r = 0)" using gp + by (simp add: mult_eq_0_iff) + finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} + ultimately show ?case by blast +next + case (11 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + {fix v assume "?sa = C v" hence ?case using sa by simp } + moreover {assume H:"\ (\ v. ?sa = C v)" + let ?g = "numgcd ?sa" + let ?rsa = "reducecoeff ?sa" + let ?r = "Inum bs ?rsa" + have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) + {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} + with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) + hence gp: "real ?g > 0" by simp + have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) + with sa have "Inum bs a \ 0 = (real ?g * ?r \ 0)" by simp + also have "\ = (?r \ 0)" using gp + by (simp add: mult_eq_0_iff) + finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} + ultimately show ?case by blast +next + case (12 i a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + have "i=0 \ (abs i = 1 \ check_int a) \ (i\0 \ ((abs i \ 1) \ (\ check_int a)))" by auto + {assume "i=0" hence ?case using "12.hyps" by (simp add: rdvd_left_0_eq Let_def)} + moreover + {assume ai1: "abs i = 1" and ai: "check_int a" + hence "i=1 \ i= - 1" by arith + moreover {assume i1: "i = 1" + from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] + have ?case using i1 ai by simp } + moreover {assume i1: "i = - 1" + from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] + rdvd_abs1[where d="- 1" and t="Inum bs a"] + have ?case using i1 ai by simp } + ultimately have ?case by blast} + moreover + {assume inz: "i\0" and cond: "(abs i \ 1) \ (\ check_int a)" + {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond + by (cases "abs i = 1", auto simp add: int_rdvd_iff) } + moreover {assume H:"\ (\ v. ?sa = C v)" + hence th: "simpfm (Dvd i a) = Dvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond by (cases ?sa, auto simp add: Let_def split_def) + from simpnum_nz have nz:"nozerocoeff ?sa" by simp + from simpdvd [OF nz inz] th have ?case using sa by simp} + ultimately have ?case by blast} + ultimately show ?case by blast +next + case (13 i a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp + have "i=0 \ (abs i = 1 \ check_int a) \ (i\0 \ ((abs i \ 1) \ (\ check_int a)))" by auto + {assume "i=0" hence ?case using "13.hyps" by (simp add: rdvd_left_0_eq Let_def)} + moreover + {assume ai1: "abs i = 1" and ai: "check_int a" + hence "i=1 \ i= - 1" by arith + moreover {assume i1: "i = 1" + from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] + have ?case using i1 ai by simp } + moreover {assume i1: "i = - 1" + from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] + rdvd_abs1[where d="- 1" and t="Inum bs a"] + have ?case using i1 ai by simp } + ultimately have ?case by blast} + moreover + {assume inz: "i\0" and cond: "(abs i \ 1) \ (\ check_int a)" + {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond + by (cases "abs i = 1", auto simp add: int_rdvd_iff) } + moreover {assume H:"\ (\ v. ?sa = C v)" + hence th: "simpfm (NDvd i a) = NDvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond + by (cases ?sa, auto simp add: Let_def split_def) + from simpnum_nz have nz:"nozerocoeff ?sa" by simp + from simpdvd [OF nz inz] th have ?case using sa by simp} + ultimately have ?case by blast} + ultimately show ?case by blast +qed (induct p rule: simpfm.induct, simp_all) + +lemma simpdvd_numbound0: "numbound0 t \ numbound0 (snd (simpdvd d t))" + by (simp add: simpdvd_def Let_def split_def reducecoeffh_numbound0) + +lemma simpfm_bound0[simp]: "bound0 p \ bound0 (simpfm p)" +proof(induct p rule: simpfm.induct) + case (6 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) +next + case (7 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) +next + case (8 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) +next + case (9 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) +next + case (10 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) +next + case (11 a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) +next + case (12 i a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def) +next + case (13 i a) hence nb: "numbound0 a" by simp + hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) + thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def) +qed(auto simp add: disj_def imp_def iff_def conj_def) + +lemma simpfm_qf[simp]: "qfree p \ qfree (simpfm p)" +by (induct p rule: simpfm.induct, auto simp add: Let_def) +(case_tac "simpnum a",auto simp add: split_def Let_def)+ + + + (* Generic quantifier elimination *) + +constdefs list_conj :: "fm list \ fm" + "list_conj ps \ foldr conj ps T" +lemma list_conj: "Ifm bs (list_conj ps) = (\p\ set ps. Ifm bs p)" + by (induct ps, auto simp add: list_conj_def) +lemma list_conj_qf: " \p\ set ps. qfree p \ qfree (list_conj ps)" + by (induct ps, auto simp add: list_conj_def) +lemma list_conj_nb: " \p\ set ps. bound0 p \ bound0 (list_conj ps)" + by (induct ps, auto simp add: list_conj_def) +constdefs CJNB:: "(fm \ fm) \ fm \ fm" + "CJNB f p \ (let cjs = conjuncts p ; (yes,no) = List.partition bound0 cjs + in conj (decr (list_conj yes)) (f (list_conj no)))" + +lemma CJNB_qe: + assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" + shows "\ bs p. qfree p \ qfree (CJNB qe p) \ (Ifm bs ((CJNB qe p)) = Ifm bs (E p))" +proof(clarify) + fix bs p + assume qfp: "qfree p" + let ?cjs = "conjuncts p" + let ?yes = "fst (List.partition bound0 ?cjs)" + let ?no = "snd (List.partition bound0 ?cjs)" + let ?cno = "list_conj ?no" + let ?cyes = "list_conj ?yes" + have part: "List.partition bound0 ?cjs = (?yes,?no)" by simp + from partition_P[OF part] have "\ q\ set ?yes. bound0 q" by blast + hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb) + hence yes_qf: "qfree (decr ?cyes )" by (simp add: decr_qf) + from conjuncts_qf[OF qfp] partition_set[OF part] + have " \q\ set ?no. qfree q" by auto + hence no_qf: "qfree ?cno"by (simp add: list_conj_qf) + with qe have cno_qf:"qfree (qe ?cno )" + and noE: "Ifm bs (qe ?cno) = Ifm bs (E ?cno)" by blast+ + from cno_qf yes_qf have qf: "qfree (CJNB qe p)" + by (simp add: CJNB_def Let_def conj_qf split_def) + {fix bs + from conjuncts have "Ifm bs p = (\q\ set ?cjs. Ifm bs q)" by blast + also have "\ = ((\q\ set ?yes. Ifm bs q) \ (\q\ set ?no. Ifm bs q))" + using partition_set[OF part] by auto + finally have "Ifm bs p = ((Ifm bs ?cyes) \ (Ifm bs ?cno))" using list_conj by simp} + hence "Ifm bs (E p) = (\x. (Ifm (x#bs) ?cyes) \ (Ifm (x#bs) ?cno))" by simp + also fix y have "\ = (\x. (Ifm (y#bs) ?cyes) \ (Ifm (x#bs) ?cno))" + using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast + also have "\ = (Ifm bs (decr ?cyes) \ Ifm bs (E ?cno))" + by (auto simp add: decr[OF yes_nb]) + also have "\ = (Ifm bs (conj (decr ?cyes) (qe ?cno)))" + using qe[rule_format, OF no_qf] by auto + finally have "Ifm bs (E p) = Ifm bs (CJNB qe p)" + by (simp add: Let_def CJNB_def split_def) + with qf show "qfree (CJNB qe p) \ Ifm bs (CJNB qe p) = Ifm bs (E p)" by blast +qed + +consts qelim :: "fm \ (fm \ fm) \ fm" +recdef qelim "measure fmsize" + "qelim (E p) = (\ qe. DJ (CJNB qe) (qelim p qe))" + "qelim (A p) = (\ qe. not (qe ((qelim (NOT p) qe))))" + "qelim (NOT p) = (\ qe. not (qelim p qe))" + "qelim (And p q) = (\ qe. conj (qelim p qe) (qelim q qe))" + "qelim (Or p q) = (\ qe. disj (qelim p qe) (qelim q qe))" + "qelim (Imp p q) = (\ qe. disj (qelim (NOT p) qe) (qelim q qe))" + "qelim (Iff p q) = (\ qe. iff (qelim p qe) (qelim q qe))" + "qelim p = (\ y. simpfm p)" + +lemma qelim_ci: + assumes qe_inv: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" + shows "\ bs. qfree (qelim p qe) \ (Ifm bs (qelim p qe) = Ifm bs p)" +using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]] +by(induct p rule: qelim.induct) +(auto simp del: simpfm.simps) + + +text {* The @{text "\"} Part *} +text{* Linearity for fm where Bound 0 ranges over @{text "\"} *} +consts + zsplit0 :: "num \ int \ num" (* splits the bounded from the unbounded part*) +recdef zsplit0 "measure num_size" + "zsplit0 (C c) = (0,C c)" + "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))" + "zsplit0 (CN n c a) = zsplit0 (Add (Mul c (Bound n)) a)" + "zsplit0 (CF c a b) = zsplit0 (Add (Mul c (Floor a)) b)" + "zsplit0 (Neg a) = (let (i',a') = zsplit0 a in (-i', Neg a'))" + "zsplit0 (Add a b) = (let (ia,a') = zsplit0 a ; + (ib,b') = zsplit0 b + in (ia+ib, Add a' b'))" + "zsplit0 (Sub a b) = (let (ia,a') = zsplit0 a ; + (ib,b') = zsplit0 b + in (ia-ib, Sub a' b'))" + "zsplit0 (Mul i a) = (let (i',a') = zsplit0 a in (i*i', Mul i a'))" + "zsplit0 (Floor a) = (let (i',a') = zsplit0 a in (i',Floor a'))" +(hints simp add: Let_def) + +lemma zsplit0_I: + shows "\ n a. zsplit0 t = (n,a) \ (Inum ((real (x::int)) #bs) (CN 0 n a) = Inum (real x #bs) t) \ numbound0 a" + (is "\ n a. ?S t = (n,a) \ (?I x (CN 0 n a) = ?I x t) \ ?N a") +proof(induct t rule: zsplit0.induct) + case (1 c n a) thus ?case by auto +next + case (2 m n a) thus ?case by (cases "m=0") auto +next + case (3 n i a n a') thus ?case by auto +next + case (4 c a b n a') thus ?case by auto +next + case (5 t n a) + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \ n=-?nt" using prems + by (simp add: Let_def split_def) + from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + from th2[simplified] th[simplified] show ?case by simp +next + case (6 s t n a) + let ?ns = "fst (zsplit0 s)" + let ?as = "snd (zsplit0 s)" + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abjs: "zsplit0 s = (?ns,?as)" by simp + moreover have abjt: "zsplit0 t = (?nt,?at)" by simp + ultimately have th: "a=Add ?as ?at \ n=?ns + ?nt" using prems + by (simp add: Let_def split_def) + from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast + from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (real x # bs) (CN 0 xa xb) = Inum (real x # bs) t \ numbound0 xb)" by simp + with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast + from th3[simplified] th2[simplified] th[simplified] show ?case + by (simp add: left_distrib) +next + case (7 s t n a) + let ?ns = "fst (zsplit0 s)" + let ?as = "snd (zsplit0 s)" + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abjs: "zsplit0 s = (?ns,?as)" by simp + moreover have abjt: "zsplit0 t = (?nt,?at)" by simp + ultimately have th: "a=Sub ?as ?at \ n=?ns - ?nt" using prems + by (simp add: Let_def split_def) + from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast + from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (real x # bs) (CN 0 xa xb) = Inum (real x # bs) t \ numbound0 xb)" by simp + with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast + from th3[simplified] th2[simplified] th[simplified] show ?case + by (simp add: left_diff_distrib) +next + case (8 i t n a) + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \ n=i*?nt" using prems + by (simp add: Let_def split_def) + from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + hence " ?I x (Mul i t) = (real i) * ?I x (CN 0 ?nt ?at)" by simp + also have "\ = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: right_distrib) + finally show ?case using th th2 by simp +next + case (9 t n a) + let ?nt = "fst (zsplit0 t)" + let ?at = "snd (zsplit0 t)" + have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a= Floor ?at \ n=?nt" using prems + by (simp add: Let_def split_def) + from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast + hence na: "?N a" using th by simp + have th': "(real ?nt)*(real x) = real (?nt * x)" by simp + have "?I x (Floor t) = ?I x (Floor (CN 0 ?nt ?at))" using th2 by simp + also have "\ = real (floor ((real ?nt)* real(x) + ?I x ?at))" by simp + also have "\ = real (floor (?I x ?at + real (?nt* x)))" by (simp add: add_ac) + also have "\ = real (floor (?I x ?at) + (?nt* x))" + using floor_add[where x="?I x ?at" and a="?nt* x"] by simp + also have "\ = real (?nt)*(real x) + real (floor (?I x ?at))" by (simp add: add_ac) + finally have "?I x (Floor t) = ?I x (CN 0 n a)" using th by simp + with na show ?case by simp +qed + +consts + iszlfm :: "fm \ real list \ bool" (* Linearity test for fm *) + zlfm :: "fm \ fm" (* Linearity transformation for fm *) +recdef iszlfm "measure size" + "iszlfm (And p q) = (\ bs. iszlfm p bs \ iszlfm q bs)" + "iszlfm (Or p q) = (\ bs. iszlfm p bs \ iszlfm q bs)" + "iszlfm (Eq (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" + "iszlfm (NEq (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" + "iszlfm (Lt (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" + "iszlfm (Le (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" + "iszlfm (Gt (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" + "iszlfm (Ge (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" + "iszlfm (Dvd i (CN 0 c e)) = + (\ bs. c>0 \ i>0 \ numbound0 e \ isint e bs)" + "iszlfm (NDvd i (CN 0 c e))= + (\ bs. c>0 \ i>0 \ numbound0 e \ isint e bs)" + "iszlfm p = (\ bs. isatom p \ (bound0 p))" + +lemma zlin_qfree: "iszlfm p bs \ qfree p" + by (induct p rule: iszlfm.induct) auto + +lemma iszlfm_gen: + assumes lp: "iszlfm p (x#bs)" + shows "\ y. iszlfm p (y#bs)" +proof + fix y + show "iszlfm p (y#bs)" + using lp + by(induct p rule: iszlfm.induct, simp_all add: numbound0_gen[rule_format, where x="x" and y="y"]) +qed + +lemma conj_zl[simp]: "iszlfm p bs \ iszlfm q bs \ iszlfm (conj p q) bs" + using conj_def by (cases p,auto) +lemma disj_zl[simp]: "iszlfm p bs \ iszlfm q bs \ iszlfm (disj p q) bs" + using disj_def by (cases p,auto) +lemma not_zl[simp]: "iszlfm p bs \ iszlfm (not p) bs" + by (induct p rule:iszlfm.induct ,auto) + +recdef zlfm "measure fmsize" + "zlfm (And p q) = conj (zlfm p) (zlfm q)" + "zlfm (Or p q) = disj (zlfm p) (zlfm q)" + "zlfm (Imp p q) = disj (zlfm (NOT p)) (zlfm q)" + "zlfm (Iff p q) = disj (conj (zlfm p) (zlfm q)) (conj (zlfm (NOT p)) (zlfm (NOT q)))" + "zlfm (Lt a) = (let (c,r) = zsplit0 a in + if c=0 then Lt r else + if c>0 then Or (Lt (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r))) + else Or (Gt (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))" + "zlfm (Le a) = (let (c,r) = zsplit0 a in + if c=0 then Le r else + if c>0 then Or (Le (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r))) + else Or (Ge (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))" + "zlfm (Gt a) = (let (c,r) = zsplit0 a in + if c=0 then Gt r else + if c>0 then Or (Gt (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) + else Or (Lt (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))" + "zlfm (Ge a) = (let (c,r) = zsplit0 a in + if c=0 then Ge r else + if c>0 then Or (Ge (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) + else Or (Le (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))" + "zlfm (Eq a) = (let (c,r) = zsplit0 a in + if c=0 then Eq r else + if c>0 then (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Eq (Add (Floor (Neg r)) r))) + else (And (Eq (CN 0 (-c) (Floor (Neg r)))) (Eq (Add (Floor (Neg r)) r))))" + "zlfm (NEq a) = (let (c,r) = zsplit0 a in + if c=0 then NEq r else + if c>0 then (Or (NEq (CN 0 c (Neg (Floor (Neg r))))) (NEq (Add (Floor (Neg r)) r))) + else (Or (NEq (CN 0 (-c) (Floor (Neg r)))) (NEq (Add (Floor (Neg r)) r))))" + "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a) + else (let (c,r) = zsplit0 a in + if c=0 then Dvd (abs i) r else + if c>0 then And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 c (Floor r))) + else And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 (-c) (Neg (Floor r))))))" + "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a) + else (let (c,r) = zsplit0 a in + if c=0 then NDvd (abs i) r else + if c>0 then Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 c (Floor r))) + else Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 (-c) (Neg (Floor r))))))" + "zlfm (NOT (And p q)) = disj (zlfm (NOT p)) (zlfm (NOT q))" + "zlfm (NOT (Or p q)) = conj (zlfm (NOT p)) (zlfm (NOT q))" + "zlfm (NOT (Imp p q)) = conj (zlfm p) (zlfm (NOT q))" + "zlfm (NOT (Iff p q)) = disj (conj(zlfm p) (zlfm(NOT q))) (conj (zlfm(NOT p)) (zlfm q))" + "zlfm (NOT (NOT p)) = zlfm p" + "zlfm (NOT T) = F" + "zlfm (NOT F) = T" + "zlfm (NOT (Lt a)) = zlfm (Ge a)" + "zlfm (NOT (Le a)) = zlfm (Gt a)" + "zlfm (NOT (Gt a)) = zlfm (Le a)" + "zlfm (NOT (Ge a)) = zlfm (Lt a)" + "zlfm (NOT (Eq a)) = zlfm (NEq a)" + "zlfm (NOT (NEq a)) = zlfm (Eq a)" + "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)" + "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)" + "zlfm p = p" (hints simp add: fmsize_pos) + +lemma split_int_less_real: + "(real (a::int) < b) = (a < floor b \ (a = floor b \ real (floor b) < b))" +proof( auto) + assume alb: "real a < b" and agb: "\ a < floor b" + from agb have "floor b \ a" by simp hence th: "b < real a + 1" by (simp only: floor_le_eq) + from floor_eq[OF alb th] show "a= floor b" by simp +next + assume alb: "a < floor b" + hence "real a < real (floor b)" by simp + moreover have "real (floor b) \ b" by simp ultimately show "real a < b" by arith +qed + +lemma split_int_less_real': + "(real (a::int) + b < 0) = (real a - real (floor(-b)) < 0 \ (real a - real (floor (-b)) = 0 \ real (floor (-b)) + b < 0))" +proof- + have "(real a + b <0) = (real a < -b)" by arith + with split_int_less_real[where a="a" and b="-b"] show ?thesis by arith +qed + +lemma split_int_gt_real': + "(real (a::int) + b > 0) = (real a + real (floor b) > 0 \ (real a + real (floor b) = 0 \ real (floor b) - b < 0))" +proof- + have th: "(real a + b >0) = (real (-a) + (-b)< 0)" by arith + show ?thesis using myless[rule_format, where b="real (floor b)"] + by (simp only:th split_int_less_real'[where a="-a" and b="-b"]) + (simp add: algebra_simps diff_def[symmetric],arith) +qed + +lemma split_int_le_real: + "(real (a::int) \ b) = (a \ floor b \ (a = floor b \ real (floor b) < b))" +proof( auto) + assume alb: "real a \ b" and agb: "\ a \ floor b" + from alb have "floor (real a) \ floor b " by (simp only: floor_mono2) + hence "a \ floor b" by simp with agb show "False" by simp +next + assume alb: "a \ floor b" + hence "real a \ real (floor b)" by (simp only: floor_mono2) + also have "\\ b" by simp finally show "real a \ b" . +qed + +lemma split_int_le_real': + "(real (a::int) + b \ 0) = (real a - real (floor(-b)) \ 0 \ (real a - real (floor (-b)) = 0 \ real (floor (-b)) + b < 0))" +proof- + have "(real a + b \0) = (real a \ -b)" by arith + with split_int_le_real[where a="a" and b="-b"] show ?thesis by arith +qed + +lemma split_int_ge_real': + "(real (a::int) + b \ 0) = (real a + real (floor b) \ 0 \ (real a + real (floor b) = 0 \ real (floor b) - b < 0))" +proof- + have th: "(real a + b \0) = (real (-a) + (-b) \ 0)" by arith + show ?thesis by (simp only: th split_int_le_real'[where a="-a" and b="-b"]) + (simp add: algebra_simps diff_def[symmetric],arith) +qed + +lemma split_int_eq_real: "(real (a::int) = b) = ( a = floor b \ b = real (floor b))" (is "?l = ?r") +by auto + +lemma split_int_eq_real': "(real (a::int) + b = 0) = ( a - floor (-b) = 0 \ real (floor (-b)) + b = 0)" (is "?l = ?r") +proof- + have "?l = (real a = -b)" by arith + with split_int_eq_real[where a="a" and b="-b"] show ?thesis by simp arith +qed + +lemma zlfm_I: + assumes qfp: "qfree p" + shows "(Ifm (real i #bs) (zlfm p) = Ifm (real i# bs) p) \ iszlfm (zlfm p) (real (i::int) #bs)" + (is "(?I (?l p) = ?I p) \ ?L (?l p)") +using qfp +proof(induct p rule: zlfm.induct) + case (5 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith + moreover + {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] + by (cases "?r", simp_all add: Let_def split_def,case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Lt a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def) + also have "\ = (?I (?l (Lt a)))" apply (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) by (simp add: Ia cp cnz Let_def split_def diff_def) + finally have ?case using l by simp} + moreover + {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Lt a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def) + also from cn cnz have "\ = (?I (?l (Lt a)))" by (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith) + finally have ?case using l by simp} + ultimately show ?case by blast +next + case (6 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith + moreover + {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat",simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Le a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Le a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) + also have "\ = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def) + finally have ?case using l by simp} + moreover + {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Le a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Le a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) + also from cn cnz have "\ = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac ,arith) + finally have ?case using l by simp} + ultimately show ?case by blast +next + case (7 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith + moreover + {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Gt a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def) + also have "\ = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def) + finally have ?case using l by simp} + moreover + {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Gt a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def) + also from cn cnz have "\ = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith) + finally have ?case using l by simp} + ultimately show ?case by blast +next + case (8 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith + moreover + {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Ge a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Ge a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) + also have "\ = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def) + finally have ?case using l by simp} + moreover + {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Ge a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Ge a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) + also from cn cnz have "\ = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith) + finally have ?case using l by simp} + ultimately show ?case by blast +next + case (9 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith + moreover + {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Eq a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def) + also have "\ = (?I (?l (Eq a)))" using cp cnz by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult) + finally have ?case using l by simp} + moreover + {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Eq a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def) + also from cn cnz have "\ = (?I (?l (Eq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult,arith) + finally have ?case using l by simp} + ultimately show ?case by blast +next + case (10 a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith + moreover + {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (NEq a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (NEq a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) + also have "\ = (?I (?l (NEq a)))" using cp cnz by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult) + finally have ?case using l by simp} + moreover + {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (NEq a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (NEq a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) + also from cn cnz have "\ = (?I (?l (NEq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult,arith) + finally have ?case using l by simp} + ultimately show ?case by blast +next + case (11 j a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0 \ ?c\0) \ (j\ 0 \ ?c<0 \ ?c\0)" by arith + moreover + {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def) + hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)} + moreover + {assume "?c=0" and "j\0" hence ?case + using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" + using Ia by (simp add: Let_def split_def) + also have "\ = (real (abs j) rdvd real (?c*i) + (?N ?r))" + by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp + also have "\ = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ + (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" + by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) + also have "\ = (?I (?l (Dvd j a)))" using cp cnz jnz + by (simp add: Let_def split_def int_rdvd_iff[symmetric] + del: real_of_int_mult) (auto simp add: add_ac) + finally have ?case using l jnz by simp } + moreover + {assume cn: "?c < 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" + using Ia by (simp add: Let_def split_def) + also have "\ = (real (abs j) rdvd real (?c*i) + (?N ?r))" + by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp + also have "\ = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ + (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" + by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) + also have "\ = (?I (?l (Dvd j a)))" using cn cnz jnz + using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric] + by (simp add: Let_def split_def int_rdvd_iff[symmetric] + del: real_of_int_mult) (auto simp add: add_ac) + finally have ?case using l jnz by blast } + ultimately show ?case by blast +next + case (12 j a) + let ?c = "fst (zsplit0 a)" + let ?r = "snd (zsplit0 a)" + have spl: "zsplit0 a = (?c,?r)" by simp + from zsplit0_I[OF spl, where x="i" and bs="bs"] + have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto + let ?N = "\ t. Inum (real i#bs) t" + have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0 \ ?c\0) \ (j\ 0 \ ?c<0 \ ?c\0)" by arith + moreover + {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def) + hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)} + moreover + {assume "?c=0" and "j\0" hence ?case + using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"] + by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} + moreover + {assume cp: "?c > 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (NDvd j a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (NDvd j a) = (\ (real j rdvd (real (?c * i) + (?N ?r))))" + using Ia by (simp add: Let_def split_def) + also have "\ = (\ (real (abs j) rdvd real (?c*i) + (?N ?r)))" + by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp + also have "\ = (\ ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ + (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" + by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) + also have "\ = (?I (?l (NDvd j a)))" using cp cnz jnz + by (simp add: Let_def split_def int_rdvd_iff[symmetric] + del: real_of_int_mult) (auto simp add: add_ac) + finally have ?case using l jnz by simp } + moreover + {assume cn: "?c < 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (NDvd j a))" + by (simp add: nb Let_def split_def isint_Floor isint_neg) + have "?I (NDvd j a) = (\ (real j rdvd (real (?c * i) + (?N ?r))))" + using Ia by (simp add: Let_def split_def) + also have "\ = (\ (real (abs j) rdvd real (?c*i) + (?N ?r)))" + by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp + also have "\ = (\ ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ + (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" + by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) + also have "\ = (?I (?l (NDvd j a)))" using cn cnz jnz + using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric] + by (simp add: Let_def split_def int_rdvd_iff[symmetric] + del: real_of_int_mult) (auto simp add: add_ac) + finally have ?case using l jnz by blast } + ultimately show ?case by blast +qed auto + +text{* plusinf : Virtual substitution of @{text "+\"} + minusinf: Virtual substitution of @{text "-\"} + @{text "\"} Compute lcm @{text "d| Dvd d c*x+t \ p"} + @{text "d\"} checks if a given l divides all the ds above*} + +consts + plusinf:: "fm \ fm" + minusinf:: "fm \ fm" + \ :: "fm \ int" + d\ :: "fm \ int \ bool" + +recdef minusinf "measure size" + "minusinf (And p q) = conj (minusinf p) (minusinf q)" + "minusinf (Or p q) = disj (minusinf p) (minusinf q)" + "minusinf (Eq (CN 0 c e)) = F" + "minusinf (NEq (CN 0 c e)) = T" + "minusinf (Lt (CN 0 c e)) = T" + "minusinf (Le (CN 0 c e)) = T" + "minusinf (Gt (CN 0 c e)) = F" + "minusinf (Ge (CN 0 c e)) = F" + "minusinf p = p" + +lemma minusinf_qfree: "qfree p \ qfree (minusinf p)" + by (induct p rule: minusinf.induct, auto) + +recdef plusinf "measure size" + "plusinf (And p q) = conj (plusinf p) (plusinf q)" + "plusinf (Or p q) = disj (plusinf p) (plusinf q)" + "plusinf (Eq (CN 0 c e)) = F" + "plusinf (NEq (CN 0 c e)) = T" + "plusinf (Lt (CN 0 c e)) = F" + "plusinf (Le (CN 0 c e)) = F" + "plusinf (Gt (CN 0 c e)) = T" + "plusinf (Ge (CN 0 c e)) = T" + "plusinf p = p" + +recdef \ "measure size" + "\ (And p q) = zlcm (\ p) (\ q)" + "\ (Or p q) = zlcm (\ p) (\ q)" + "\ (Dvd i (CN 0 c e)) = i" + "\ (NDvd i (CN 0 c e)) = i" + "\ p = 1" + +recdef d\ "measure size" + "d\ (And p q) = (\ d. d\ p d \ d\ q d)" + "d\ (Or p q) = (\ d. d\ p d \ d\ q d)" + "d\ (Dvd i (CN 0 c e)) = (\ d. i dvd d)" + "d\ (NDvd i (CN 0 c e)) = (\ d. i dvd d)" + "d\ p = (\ d. True)" + +lemma delta_mono: + assumes lin: "iszlfm p bs" + and d: "d dvd d'" + and ad: "d\ p d" + shows "d\ p d'" + using lin ad d +proof(induct p rule: iszlfm.induct) + case (9 i c e) thus ?case using d + by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) +next + case (10 i c e) thus ?case using d + by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) +qed simp_all + +lemma \ : assumes lin:"iszlfm p bs" + shows "d\ p (\ p) \ \ p >0" +using lin +proof (induct p rule: iszlfm.induct) + case (1 p q) + let ?d = "\ (And p q)" + from prems zlcm_pos have dp: "?d >0" by simp + have d1: "\ p dvd \ (And p q)" using prems by simp + hence th: "d\ p ?d" + using delta_mono prems by (auto simp del: dvd_zlcm_self1) + have "\ q dvd \ (And p q)" using prems by simp + hence th': "d\ q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2) + from th th' dp show ?case by simp +next + case (2 p q) + let ?d = "\ (And p q)" + from prems zlcm_pos have dp: "?d >0" by simp + have "\ p dvd \ (And p q)" using prems by simp hence th: "d\ p ?d" using delta_mono prems + by (auto simp del: dvd_zlcm_self1) + have "\ q dvd \ (And p q)" using prems by simp hence th': "d\ q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2) + from th th' dp show ?case by simp +qed simp_all + + +lemma minusinf_inf: + assumes linp: "iszlfm p (a # bs)" + shows "\ (z::int). \ x < z. Ifm ((real x)#bs) (minusinf p) = Ifm ((real x)#bs) p" + (is "?P p" is "\ (z::int). \ x < z. ?I x (?M p) = ?I x p") +using linp +proof (induct p rule: minusinf.induct) + case (1 f g) + from prems have "?P f" by simp + then obtain z1 where z1_def: "\ x < z1. ?I x (?M f) = ?I x f" by blast + from prems have "?P g" by simp + then obtain z2 where z2_def: "\ x < z2. ?I x (?M g) = ?I x g" by blast + let ?z = "min z1 z2" + from z1_def z2_def have "\ x < ?z. ?I x (?M (And f g)) = ?I x (And f g)" by simp + thus ?case by blast +next + case (2 f g) from prems have "?P f" by simp + then obtain z1 where z1_def: "\ x < z1. ?I x (?M f) = ?I x f" by blast + from prems have "?P g" by simp + then obtain z2 where z2_def: "\ x < z2. ?I x (?M g) = ?I x g" by blast + let ?z = "min z1 z2" + from z1_def z2_def have "\ x < ?z. ?I x (?M (Or f g)) = ?I x (Or f g)" by simp + thus ?case by blast +next + case (3 c e) + from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp + from prems have nbe: "numbound0 e" by simp + fix y + have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Eq (CN 0 c e))) = ?I x (Eq (CN 0 c e))" + proof (simp add: less_floor_eq , rule allI, rule impI) + fix x + assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" + hence th1:"real x < - (Inum (y # bs) e / real c)" by simp + with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" + by (simp only: real_mult_less_mono2[OF rcpos th1]) + hence "real c * real x + Inum (y # bs) e \ 0"using rcpos by simp + thus "real c * real x + Inum (real x # bs) e \ 0" + using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] by simp + qed + thus ?case by blast +next + case (4 c e) + from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp + from prems have nbe: "numbound0 e" by simp + fix y + have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (NEq (CN 0 c e))) = ?I x (NEq (CN 0 c e))" + proof (simp add: less_floor_eq , rule allI, rule impI) + fix x + assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" + hence th1:"real x < - (Inum (y # bs) e / real c)" by simp + with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" + by (simp only: real_mult_less_mono2[OF rcpos th1]) + hence "real c * real x + Inum (y # bs) e \ 0"using rcpos by simp + thus "real c * real x + Inum (real x # bs) e \ 0" + using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] by simp + qed + thus ?case by blast +next + case (5 c e) + from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp + from prems have nbe: "numbound0 e" by simp + fix y + have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Lt (CN 0 c e))) = ?I x (Lt (CN 0 c e))" + proof (simp add: less_floor_eq , rule allI, rule impI) + fix x + assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" + hence th1:"real x < - (Inum (y # bs) e / real c)" by simp + with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" + by (simp only: real_mult_less_mono2[OF rcpos th1]) + thus "real c * real x + Inum (real x # bs) e < 0" + using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp + qed + thus ?case by blast +next + case (6 c e) + from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp + from prems have nbe: "numbound0 e" by simp + fix y + have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Le (CN 0 c e))) = ?I x (Le (CN 0 c e))" + proof (simp add: less_floor_eq , rule allI, rule impI) + fix x + assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" + hence th1:"real x < - (Inum (y # bs) e / real c)" by simp + with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" + by (simp only: real_mult_less_mono2[OF rcpos th1]) + thus "real c * real x + Inum (real x # bs) e \ 0" + using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp + qed + thus ?case by blast +next + case (7 c e) + from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp + from prems have nbe: "numbound0 e" by simp + fix y + have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Gt (CN 0 c e))) = ?I x (Gt (CN 0 c e))" + proof (simp add: less_floor_eq , rule allI, rule impI) + fix x + assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" + hence th1:"real x < - (Inum (y # bs) e / real c)" by simp + with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" + by (simp only: real_mult_less_mono2[OF rcpos th1]) + thus "\ (real c * real x + Inum (real x # bs) e>0)" + using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp + qed + thus ?case by blast +next + case (8 c e) + from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp + from prems have nbe: "numbound0 e" by simp + fix y + have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Ge (CN 0 c e))) = ?I x (Ge (CN 0 c e))" + proof (simp add: less_floor_eq , rule allI, rule impI) + fix x + assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" + hence th1:"real x < - (Inum (y # bs) e / real c)" by simp + with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" + by (simp only: real_mult_less_mono2[OF rcpos th1]) + thus "\ real c * real x + Inum (real x # bs) e \ 0" + using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp + qed + thus ?case by blast +qed simp_all + +lemma minusinf_repeats: + assumes d: "d\ p d" and linp: "iszlfm p (a # bs)" + shows "Ifm ((real(x - k*d))#bs) (minusinf p) = Ifm (real x #bs) (minusinf p)" +using linp d +proof(induct p rule: iszlfm.induct) + case (9 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ + hence "\ k. d=i*k" by (simp add: dvd_def) + then obtain "di" where di_def: "d=i*di" by blast + show ?case + proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="real x - real k * real d" and b'="real x"] right_diff_distrib, rule iffI) + assume + "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" + (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt") + hence "\ (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def) + hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" + by (simp add: algebra_simps di_def) + hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))" + by (simp add: algebra_simps) + hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast + thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp + next + assume + "real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e") + hence "\ (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def) + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real d)" by simp + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real i * real di)" by (simp add: di_def) + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real (l - c*k*di))" by (simp add: algebra_simps) + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)" + by blast + thus "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" using rdvd_def by simp + qed +next + case (10 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ + hence "\ k. d=i*k" by (simp add: dvd_def) + then obtain "di" where di_def: "d=i*di" by blast + show ?case + proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="real x - real k * real d" and b'="real x"] right_diff_distrib, rule iffI) + assume + "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" + (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt") + hence "\ (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def) + hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" + by (simp add: algebra_simps di_def) + hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))" + by (simp add: algebra_simps) + hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast + thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp + next + assume + "real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e") + hence "\ (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def) + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real d)" by simp + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real i * real di)" by (simp add: di_def) + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real (l - c*k*di))" by (simp add: algebra_simps) + hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)" + by blast + thus "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" using rdvd_def by simp + qed +qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="real(x - k*d)" and b'="real x"] simp del: real_of_int_mult real_of_int_diff) + +lemma minusinf_ex: + assumes lin: "iszlfm p (real (a::int) #bs)" + and exmi: "\ (x::int). Ifm (real x#bs) (minusinf p)" (is "\ x. ?P1 x") + shows "\ (x::int). Ifm (real x#bs) p" (is "\ x. ?P x") +proof- + let ?d = "\ p" + from \ [OF lin] have dpos: "?d >0" by simp + from \ [OF lin] have alld: "d\ p ?d" by simp + from minusinf_repeats[OF alld lin] have th1:"\ x k. ?P1 x = ?P1 (x - (k * ?d))" by simp + from minusinf_inf[OF lin] have th2:"\ z. \ x. x (?P x = ?P1 x)" by blast + from minusinfinity [OF dpos th1 th2] exmi show ?thesis by blast +qed + +lemma minusinf_bex: + assumes lin: "iszlfm p (real (a::int) #bs)" + shows "(\ (x::int). Ifm (real x#bs) (minusinf p)) = + (\ (x::int)\ {1..\ p}. Ifm (real x#bs) (minusinf p))" + (is "(\ x. ?P x) = _") +proof- + let ?d = "\ p" + from \ [OF lin] have dpos: "?d >0" by simp + from \ [OF lin] have alld: "d\ p ?d" by simp + from minusinf_repeats[OF alld lin] have th1:"\ x k. ?P x = ?P (x - (k * ?d))" by simp + from periodic_finite_ex[OF dpos th1] show ?thesis by blast +qed + +lemma dvd1_eq1: "x >0 \ (x::int) dvd 1 = (x = 1)" by auto + +consts + a\ :: "fm \ int \ fm" (* adjusts the coeffitients of a formula *) + d\ :: "fm \ int \ bool" (* tests if all coeffs c of c divide a given l*) + \ :: "fm \ int" (* computes the lcm of all coefficients of x*) + \ :: "fm \ num list" + \ :: "fm \ num list" + +recdef a\ "measure size" + "a\ (And p q) = (\ k. And (a\ p k) (a\ q k))" + "a\ (Or p q) = (\ k. Or (a\ p k) (a\ q k))" + "a\ (Eq (CN 0 c e)) = (\ k. Eq (CN 0 1 (Mul (k div c) e)))" + "a\ (NEq (CN 0 c e)) = (\ k. NEq (CN 0 1 (Mul (k div c) e)))" + "a\ (Lt (CN 0 c e)) = (\ k. Lt (CN 0 1 (Mul (k div c) e)))" + "a\ (Le (CN 0 c e)) = (\ k. Le (CN 0 1 (Mul (k div c) e)))" + "a\ (Gt (CN 0 c e)) = (\ k. Gt (CN 0 1 (Mul (k div c) e)))" + "a\ (Ge (CN 0 c e)) = (\ k. Ge (CN 0 1 (Mul (k div c) e)))" + "a\ (Dvd i (CN 0 c e)) =(\ k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" + "a\ (NDvd i (CN 0 c e))=(\ k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" + "a\ p = (\ k. p)" + +recdef d\ "measure size" + "d\ (And p q) = (\ k. (d\ p k) \ (d\ q k))" + "d\ (Or p q) = (\ k. (d\ p k) \ (d\ q k))" + "d\ (Eq (CN 0 c e)) = (\ k. c dvd k)" + "d\ (NEq (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Lt (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Le (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Gt (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Ge (CN 0 c e)) = (\ k. c dvd k)" + "d\ (Dvd i (CN 0 c e)) =(\ k. c dvd k)" + "d\ (NDvd i (CN 0 c e))=(\ k. c dvd k)" + "d\ p = (\ k. True)" + +recdef \ "measure size" + "\ (And p q) = zlcm (\ p) (\ q)" + "\ (Or p q) = zlcm (\ p) (\ q)" + "\ (Eq (CN 0 c e)) = c" + "\ (NEq (CN 0 c e)) = c" + "\ (Lt (CN 0 c e)) = c" + "\ (Le (CN 0 c e)) = c" + "\ (Gt (CN 0 c e)) = c" + "\ (Ge (CN 0 c e)) = c" + "\ (Dvd i (CN 0 c e)) = c" + "\ (NDvd i (CN 0 c e))= c" + "\ p = 1" + +recdef \ "measure size" + "\ (And p q) = (\ p @ \ q)" + "\ (Or p q) = (\ p @ \ q)" + "\ (Eq (CN 0 c e)) = [Sub (C -1) e]" + "\ (NEq (CN 0 c e)) = [Neg e]" + "\ (Lt (CN 0 c e)) = []" + "\ (Le (CN 0 c e)) = []" + "\ (Gt (CN 0 c e)) = [Neg e]" + "\ (Ge (CN 0 c e)) = [Sub (C -1) e]" + "\ p = []" + +recdef \ "measure size" + "\ (And p q) = (\ p @ \ q)" + "\ (Or p q) = (\ p @ \ q)" + "\ (Eq (CN 0 c e)) = [Add (C -1) e]" + "\ (NEq (CN 0 c e)) = [e]" + "\ (Lt (CN 0 c e)) = [e]" + "\ (Le (CN 0 c e)) = [Add (C -1) e]" + "\ (Gt (CN 0 c e)) = []" + "\ (Ge (CN 0 c e)) = []" + "\ p = []" +consts mirror :: "fm \ fm" +recdef mirror "measure size" + "mirror (And p q) = And (mirror p) (mirror q)" + "mirror (Or p q) = Or (mirror p) (mirror q)" + "mirror (Eq (CN 0 c e)) = Eq (CN 0 c (Neg e))" + "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))" + "mirror (Lt (CN 0 c e)) = Gt (CN 0 c (Neg e))" + "mirror (Le (CN 0 c e)) = Ge (CN 0 c (Neg e))" + "mirror (Gt (CN 0 c e)) = Lt (CN 0 c (Neg e))" + "mirror (Ge (CN 0 c e)) = Le (CN 0 c (Neg e))" + "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))" + "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))" + "mirror p = p" + +lemma mirror\\: + assumes lp: "iszlfm p (a#bs)" + shows "(Inum (real (i::int)#bs)) ` set (\ p) = (Inum (real i#bs)) ` set (\ (mirror p))" +using lp +by (induct p rule: mirror.induct, auto) + +lemma mirror: + assumes lp: "iszlfm p (a#bs)" + shows "Ifm (real (x::int)#bs) (mirror p) = Ifm (real (- x)#bs) p" +using lp +proof(induct p rule: iszlfm.induct) + case (9 j c e) + have th: "(real j rdvd real c * real x - Inum (real x # bs) e) = + (real j rdvd - (real c * real x - Inum (real x # bs) e))" + by (simp only: rdvd_minus[symmetric]) + from prems th show ?case + by (simp add: algebra_simps + numbound0_I[where bs="bs" and b'="real x" and b="- real x"]) +next + case (10 j c e) + have th: "(real j rdvd real c * real x - Inum (real x # bs) e) = + (real j rdvd - (real c * real x - Inum (real x # bs) e))" + by (simp only: rdvd_minus[symmetric]) + from prems th show ?case + by (simp add: algebra_simps + numbound0_I[where bs="bs" and b'="real x" and b="- real x"]) +qed (auto simp add: numbound0_I[where bs="bs" and b="real x" and b'="- real x"] nth_pos2) + +lemma mirror_l: "iszlfm p (a#bs) \ iszlfm (mirror p) (a#bs)" +by (induct p rule: mirror.induct, auto simp add: isint_neg) + +lemma mirror_d\: "iszlfm p (a#bs) \ d\ p 1 + \ iszlfm (mirror p) (a#bs) \ d\ (mirror p) 1" +by (induct p rule: mirror.induct, auto simp add: isint_neg) + +lemma mirror_\: "iszlfm p (a#bs) \ \ (mirror p) = \ p" +by (induct p rule: mirror.induct,auto) + + +lemma mirror_ex: + assumes lp: "iszlfm p (real (i::int)#bs)" + shows "(\ (x::int). Ifm (real x#bs) (mirror p)) = (\ (x::int). Ifm (real x#bs) p)" + (is "(\ x. ?I x ?mp) = (\ x. ?I x p)") +proof(auto) + fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast + thus "\ x. ?I x p" by blast +next + fix x assume "?I x p" hence "?I (- x) ?mp" + using mirror[OF lp, where x="- x", symmetric] by auto + thus "\ x. ?I x ?mp" by blast +qed + +lemma \_numbound0: assumes lp: "iszlfm p bs" + shows "\ b\ set (\ p). numbound0 b" + using lp by (induct p rule: \.induct,auto) + +lemma d\_mono: + assumes linp: "iszlfm p (a #bs)" + and dr: "d\ p l" + and d: "l dvd l'" + shows "d\ p l'" +using dr linp zdvd_trans[where n="l" and k="l'", simplified d] +by (induct p rule: iszlfm.induct) simp_all + +lemma \_l: assumes lp: "iszlfm p (a#bs)" + shows "\ b\ set (\ p). numbound0 b \ isint b (a#bs)" +using lp +by(induct p rule: \.induct, auto simp add: isint_add isint_c) + +lemma \: + assumes linp: "iszlfm p (a #bs)" + shows "\ p > 0 \ d\ p (\ p)" +using linp +proof(induct p rule: iszlfm.induct) + case (1 p q) + from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp + from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp + from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] + d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] + dl1 dl2 show ?case by (auto simp add: zlcm_pos) +next + case (2 p q) + from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp + from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp + from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] + d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] + dl1 dl2 show ?case by (auto simp add: zlcm_pos) +qed (auto simp add: zlcm_pos) + +lemma a\: assumes linp: "iszlfm p (a #bs)" and d: "d\ p l" and lp: "l > 0" + shows "iszlfm (a\ p l) (a #bs) \ d\ (a\ p l) 1 \ (Ifm (real (l * x) #bs) (a\ p l) = Ifm ((real x)#bs) p)" +using linp d +proof (induct p rule: iszlfm.induct) + case (5 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(real l * real x + real (l div c) * Inum (real x # bs) e < (0\real)) = + (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e < 0)" + by simp + also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) < (real (l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (real c * real x + Inum (real x # bs) e < 0)" + using mult_less_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp +next + case (6 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(real l * real x + real (l div c) * Inum (real x # bs) e \ (0\real)) = + (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \ 0)" + by simp + also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) \ (real (l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (real c * real x + Inum (real x # bs) e \ 0)" + using mult_le_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp +next + case (7 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(real l * real x + real (l div c) * Inum (real x # bs) e > (0\real)) = + (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e > 0)" + by simp + also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) > (real (l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (real c * real x + Inum (real x # bs) e > 0)" + using zero_less_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp +next + case (8 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(real l * real x + real (l div c) * Inum (real x # bs) e \ (0\real)) = + (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \ 0)" + by simp + also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) \ (real (l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (real c * real x + Inum (real x # bs) e \ 0)" + using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp +next + case (3 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(real l * real x + real (l div c) * Inum (real x # bs) e = (0\real)) = + (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = 0)" + by simp + also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) = (real (l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (real c * real x + Inum (real x # bs) e = 0)" + using mult_eq_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp +next + case (4 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(real l * real x + real (l div c) * Inum (real x # bs) e \ (0\real)) = + (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \ 0)" + by simp + also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) \ (real (l div c)) * 0)" by (simp add: algebra_simps) + also have "\ = (real c * real x + Inum (real x # bs) e \ 0)" + using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp +next + case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and jp: "j > 0" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(\ (k::int). real l * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k) = (\ (k::int). real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k)" by simp + also have "\ = (\ (k::int). real (l div c) * (real c * real x + Inum (real x # bs) e - real j * real k) = real (l div c)*0)" by (simp add: algebra_simps) + also fix k have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)" + using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e - real j * real k"] ldcp by simp + also have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] rdvd_def be isint_Mul[OF ei] mult_strict_mono[OF ldcp jp ldcp ] by simp +next + case (10 j c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and jp: "j > 0" and d': "c dvd l" by simp+ + from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) + from cp have cnz: "c \ 0" by simp + have "c div c\ l div c" + by (simp add: zdiv_mono1[OF clel cp]) + then have ldcp:"0 < l div c" + by (simp add: zdiv_self[OF cnz]) + 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 + hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] + by simp + hence "(\ (k::int). real l * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k) = (\ (k::int). real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k)" by simp + also have "\ = (\ (k::int). real (l div c) * (real c * real x + Inum (real x # bs) e - real j * real k) = real (l div c)*0)" by (simp add: algebra_simps) + also fix k have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)" + using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e - real j * real k"] ldcp by simp + also have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp + finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] rdvd_def be isint_Mul[OF ei] mult_strict_mono[OF ldcp jp ldcp ] by simp +qed (simp_all add: nth_pos2 numbound0_I[where bs="bs" and b="real (l * x)" and b'="real x"] isint_Mul del: real_of_int_mult) + +lemma a\_ex: assumes linp: "iszlfm p (a#bs)" and d: "d\ p l" and lp: "l>0" + shows "(\ x. l dvd x \ Ifm (real x #bs) (a\ p l)) = (\ (x::int). Ifm (real x#bs) p)" + (is "(\ x. l dvd x \ ?P x) = (\ x. ?P' x)") +proof- + have "(\ x. l dvd x \ ?P x) = (\ (x::int). ?P (l*x))" + using unity_coeff_ex[where l="l" and P="?P", simplified] by simp + also have "\ = (\ (x::int). ?P' x)" using a\[OF linp d lp] by simp + finally show ?thesis . +qed + +lemma \: + assumes lp: "iszlfm p (a#bs)" + and u: "d\ p 1" + and d: "d\ p d" + and dp: "d > 0" + and nob: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). real x = b + real j)" + and p: "Ifm (real x#bs) p" (is "?P x") + shows "?P (x - d)" +using lp u d dp nob p +proof(induct p rule: iszlfm.induct) + case (5 c e) hence c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ + with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems + show ?case by (simp del: real_of_int_minus) +next + case (6 c e) hence c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ + with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems + show ?case by (simp del: real_of_int_minus) +next + case (7 c e) hence p: "Ifm (real x #bs) (Gt (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" and ie1:"isint e (a#bs)" using dvd1_eq1[where x="c"] by simp+ + let ?e = "Inum (real x # bs) e" + from ie1 have ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="a#bs"] + numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"] + by (simp add: isint_iff) + {assume "real (x-d) +?e > 0" hence ?case using c1 + numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] + by (simp del: real_of_int_minus)} + moreover + {assume H: "\ real (x-d) + ?e > 0" + let ?v="Neg e" + have vb: "?v \ set (\ (Gt (CN 0 c e)))" by simp + from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]] + have nob: "\ (\ j\ {1 ..d}. real x = - ?e + real j)" by auto + from H p have "real x + ?e > 0 \ real x + ?e \ real d" by (simp add: c1) + hence "real (x + floor ?e) > real (0::int) \ real (x + floor ?e) \ real d" + using ie by simp + hence "x + floor ?e \ 1 \ x + floor ?e \ d" by simp + hence "\ (j::int) \ {1 .. d}. j = x + floor ?e" by simp + hence "\ (j::int) \ {1 .. d}. real x = real (- floor ?e + j)" + by (simp only: real_of_int_inject) (simp add: algebra_simps) + hence "\ (j::int) \ {1 .. d}. real x = - ?e + real j" + by (simp add: ie[simplified isint_iff]) + with nob have ?case by auto} + ultimately show ?case by blast +next + case (8 c e) hence p: "Ifm (real x #bs) (Ge (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" + and ie1:"isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+ + let ?e = "Inum (real x # bs) e" + from ie1 have ie: "real (floor ?e) = ?e" using numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real x)#bs"] + by (simp add: isint_iff) + {assume "real (x-d) +?e \ 0" hence ?case using c1 + numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] + by (simp del: real_of_int_minus)} + moreover + {assume H: "\ real (x-d) + ?e \ 0" + let ?v="Sub (C -1) e" + have vb: "?v \ set (\ (Ge (CN 0 c e)))" by simp + from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]] + have nob: "\ (\ j\ {1 ..d}. real x = - ?e - 1 + real j)" by auto + from H p have "real x + ?e \ 0 \ real x + ?e < real d" by (simp add: c1) + hence "real (x + floor ?e) \ real (0::int) \ real (x + floor ?e) < real d" + using ie by simp + hence "x + floor ?e +1 \ 1 \ x + floor ?e + 1 \ d" by simp + hence "\ (j::int) \ {1 .. d}. j = x + floor ?e + 1" by simp + hence "\ (j::int) \ {1 .. d}. x= - floor ?e - 1 + j" by (simp add: algebra_simps) + hence "\ (j::int) \ {1 .. d}. real x= real (- floor ?e - 1 + j)" + by (simp only: real_of_int_inject) + hence "\ (j::int) \ {1 .. d}. real x= - ?e - 1 + real j" + by (simp add: ie[simplified isint_iff]) + with nob have ?case by simp } + ultimately show ?case by blast +next + case (3 c e) hence p: "Ifm (real x #bs) (Eq (CN 0 c e))" (is "?p x") and c1: "c=1" + and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+ + let ?e = "Inum (real x # bs) e" + let ?v="(Sub (C -1) e)" + have vb: "?v \ set (\ (Eq (CN 0 c e)))" by simp + from p have "real x= - ?e" by (simp add: c1) with prems(11) show ?case using dp + by simp (erule ballE[where x="1"], + simp_all add:algebra_simps numbound0_I[OF bn,where b="real x"and b'="a"and bs="bs"]) +next + case (4 c e)hence p: "Ifm (real x #bs) (NEq (CN 0 c e))" (is "?p x") and c1: "c=1" + and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+ + let ?e = "Inum (real x # bs) e" + let ?v="Neg e" + have vb: "?v \ set (\ (NEq (CN 0 c e)))" by simp + {assume "real x - real d + Inum ((real (x -d)) # bs) e \ 0" + hence ?case by (simp add: c1)} + moreover + {assume H: "real x - real d + Inum ((real (x -d)) # bs) e = 0" + hence "real x = - Inum ((real (x -d)) # bs) e + real d" by simp + hence "real x = - Inum (a # bs) e + real d" + by (simp add: numbound0_I[OF bn,where b="real x - real d"and b'="a"and bs="bs"]) + with prems(11) have ?case using dp by simp} + ultimately show ?case by blast +next + case (9 j c e) hence p: "Ifm (real x #bs) (Dvd j (CN 0 c e))" (is "?p x") and c1: "c=1" + and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ + let ?e = "Inum (real x # bs) e" + from prems have "isint e (a #bs)" by simp + hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real x)#bs"] numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] + by (simp add: isint_iff) + from prems have id: "j dvd d" by simp + from c1 ie[symmetric] have "?p x = (real j rdvd real (x+ floor ?e))" by simp + also have "\ = (j dvd x + floor ?e)" + using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp + also have "\ = (j dvd x - d + floor ?e)" + using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp + also have "\ = (real j rdvd real (x - d + floor ?e))" + using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified] + ie by simp + also have "\ = (real j rdvd real x - real d + ?e)" + using ie by simp + finally show ?case + using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp +next + case (10 j c e) hence p: "Ifm (real x #bs) (NDvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ + let ?e = "Inum (real x # bs) e" + from prems have "isint e (a#bs)" by simp + hence ie: "real (floor ?e) = ?e" using numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real x)#bs"] + by (simp add: isint_iff) + from prems have id: "j dvd d" by simp + from c1 ie[symmetric] have "?p x = (\ real j rdvd real (x+ floor ?e))" by simp + also have "\ = (\ j dvd x + floor ?e)" + using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp + also have "\ = (\ j dvd x - d + floor ?e)" + using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp + also have "\ = (\ real j rdvd real (x - d + floor ?e))" + using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified] + ie by simp + also have "\ = (\ real j rdvd real x - real d + ?e)" + using ie by simp + finally show ?case using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp +qed (auto simp add: numbound0_I[where bs="bs" and b="real (x - d)" and b'="real x"] nth_pos2 simp del: real_of_int_diff) + +lemma \': + assumes lp: "iszlfm p (a #bs)" + and u: "d\ p 1" + and d: "d\ p d" + and dp: "d > 0" + shows "\ x. \(\(j::int) \ {1 .. d}. \ b\ set(\ p). Ifm ((Inum (a#bs) b + real j) #bs) p) \ Ifm (real x#bs) p \ Ifm (real (x - d)#bs) p" (is "\ x. ?b \ ?P x \ ?P (x - d)") +proof(clarify) + fix x + assume nb:"?b" and px: "?P x" + hence nb2: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). real x = b + real j)" + by auto + from \[OF lp u d dp nb2 px] show "?P (x -d )" . +qed + +lemma \_int: assumes lp: "iszlfm p bs" + shows "\ b\ set (\ p). isint b bs" +using lp by (induct p rule: iszlfm.induct) (auto simp add: isint_neg isint_sub) + +lemma cpmi_eq: "0 < D \ (EX z::int. ALL x. x < z --> (P x = P1 x)) +==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) +==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D)))) +==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))" +apply(rule iffI) +prefer 2 +apply(drule minusinfinity) +apply assumption+ +apply(fastsimp) +apply clarsimp +apply(subgoal_tac "!!k. 0<=k \ !x. P x \ P (x - k*D)") +apply(frule_tac x = x and z=z in decr_lemma) +apply(subgoal_tac "P1(x - (\x - z\ + 1) * D)") +prefer 2 +apply(subgoal_tac "0 <= (\x - z\ + 1)") +prefer 2 apply arith + apply fastsimp +apply(drule (1) periodic_finite_ex) +apply blast +apply(blast dest:decr_mult_lemma) +done + + +theorem cp_thm: + assumes lp: "iszlfm p (a #bs)" + and u: "d\ p 1" + and d: "d\ p d" + and dp: "d > 0" + shows "(\ (x::int). Ifm (real x #bs) p) = (\ j\ {1.. d}. Ifm (real j #bs) (minusinf p) \ (\ b \ set (\ p). Ifm ((Inum (a#bs) b + real j) #bs) p))" + (is "(\ (x::int). ?P (real x)) = (\ j\ ?D. ?M j \ (\ b\ ?B. ?P (?I b + real j)))") +proof- + from minusinf_inf[OF lp] + have th: "\(z::int). \x_int[OF lp] isint_iff[where bs="a # bs"] have B: "\ b\ ?B. real (floor (?I b)) = ?I b" by simp + from B[rule_format] + have "(\j\?D. \b\ ?B. ?P (?I b + real j)) = (\j\?D. \b\ ?B. ?P (real (floor (?I b)) + real j))" + by simp + also have "\ = (\j\?D. \b\ ?B. ?P (real (floor (?I b) + j)))" by simp + also have"\ = (\ j \ ?D. \ b \ ?B'. ?P (real (b + j)))" by blast + finally have BB': + "(\j\?D. \b\ ?B. ?P (?I b + real j)) = (\ j \ ?D. \ b \ ?B'. ?P (real (b + j)))" + by blast + hence th2: "\ x. \ (\ j \ ?D. \ b \ ?B'. ?P (real (b + j))) \ ?P (real x) \ ?P (real (x - d))" using \'[OF lp u d dp] by blast + from minusinf_repeats[OF d lp] + have th3: "\ x k. ?M x = ?M (x-k*d)" by simp + from cpmi_eq[OF dp th th2 th3] BB' show ?thesis by blast +qed + + (* Reddy and Loveland *) + + +consts + \ :: "fm \ (num \ int) list" (* Compute the Reddy and Loveland Bset*) + \\:: "fm \ num \ int \ fm" (* Performs the modified substitution of Reddy and Loveland*) + \\ :: "fm \ (num\int) list" + a\ :: "fm \ int \ fm" +recdef \ "measure size" + "\ (And p q) = (\ p @ \ q)" + "\ (Or p q) = (\ p @ \ q)" + "\ (Eq (CN 0 c e)) = [(Sub (C -1) e,c)]" + "\ (NEq (CN 0 c e)) = [(Neg e,c)]" + "\ (Lt (CN 0 c e)) = []" + "\ (Le (CN 0 c e)) = []" + "\ (Gt (CN 0 c e)) = [(Neg e, c)]" + "\ (Ge (CN 0 c e)) = [(Sub (C (-1)) e, c)]" + "\ p = []" + +recdef \\ "measure size" + "\\ (And p q) = (\ (t,k). And (\\ p (t,k)) (\\ q (t,k)))" + "\\ (Or p q) = (\ (t,k). Or (\\ p (t,k)) (\\ q (t,k)))" + "\\ (Eq (CN 0 c e)) = (\ (t,k). if k dvd c then (Eq (Add (Mul (c div k) t) e)) + else (Eq (Add (Mul c t) (Mul k e))))" + "\\ (NEq (CN 0 c e)) = (\ (t,k). if k dvd c then (NEq (Add (Mul (c div k) t) e)) + else (NEq (Add (Mul c t) (Mul k e))))" + "\\ (Lt (CN 0 c e)) = (\ (t,k). if k dvd c then (Lt (Add (Mul (c div k) t) e)) + else (Lt (Add (Mul c t) (Mul k e))))" + "\\ (Le (CN 0 c e)) = (\ (t,k). if k dvd c then (Le (Add (Mul (c div k) t) e)) + else (Le (Add (Mul c t) (Mul k e))))" + "\\ (Gt (CN 0 c e)) = (\ (t,k). if k dvd c then (Gt (Add (Mul (c div k) t) e)) + else (Gt (Add (Mul c t) (Mul k e))))" + "\\ (Ge (CN 0 c e)) = (\ (t,k). if k dvd c then (Ge (Add (Mul (c div k) t) e)) + else (Ge (Add (Mul c t) (Mul k e))))" + "\\ (Dvd i (CN 0 c e)) =(\ (t,k). if k dvd c then (Dvd i (Add (Mul (c div k) t) e)) + else (Dvd (i*k) (Add (Mul c t) (Mul k e))))" + "\\ (NDvd i (CN 0 c e))=(\ (t,k). if k dvd c then (NDvd i (Add (Mul (c div k) t) e)) + else (NDvd (i*k) (Add (Mul c t) (Mul k e))))" + "\\ p = (\ (t,k). p)" + +recdef \\ "measure size" + "\\ (And p q) = (\\ p @ \\ q)" + "\\ (Or p q) = (\\ p @ \\ q)" + "\\ (Eq (CN 0 c e)) = [(Add (C -1) e,c)]" + "\\ (NEq (CN 0 c e)) = [(e,c)]" + "\\ (Lt (CN 0 c e)) = [(e,c)]" + "\\ (Le (CN 0 c e)) = [(Add (C -1) e,c)]" + "\\ p = []" + + (* Simulates normal substituion by modifying the formula see correctness theorem *) + +recdef a\ "measure size" + "a\ (And p q) = (\ k. And (a\ p k) (a\ q k))" + "a\ (Or p q) = (\ k. Or (a\ p k) (a\ q k))" + "a\ (Eq (CN 0 c e)) = (\ k. if k dvd c then (Eq (CN 0 (c div k) e)) + else (Eq (CN 0 c (Mul k e))))" + "a\ (NEq (CN 0 c e)) = (\ k. if k dvd c then (NEq (CN 0 (c div k) e)) + else (NEq (CN 0 c (Mul k e))))" + "a\ (Lt (CN 0 c e)) = (\ k. if k dvd c then (Lt (CN 0 (c div k) e)) + else (Lt (CN 0 c (Mul k e))))" + "a\ (Le (CN 0 c e)) = (\ k. if k dvd c then (Le (CN 0 (c div k) e)) + else (Le (CN 0 c (Mul k e))))" + "a\ (Gt (CN 0 c e)) = (\ k. if k dvd c then (Gt (CN 0 (c div k) e)) + else (Gt (CN 0 c (Mul k e))))" + "a\ (Ge (CN 0 c e)) = (\ k. if k dvd c then (Ge (CN 0 (c div k) e)) + else (Ge (CN 0 c (Mul k e))))" + "a\ (Dvd i (CN 0 c e)) = (\ k. if k dvd c then (Dvd i (CN 0 (c div k) e)) + else (Dvd (i*k) (CN 0 c (Mul k e))))" + "a\ (NDvd i (CN 0 c e)) = (\ k. if k dvd c then (NDvd i (CN 0 (c div k) e)) + else (NDvd (i*k) (CN 0 c (Mul k e))))" + "a\ p = (\ k. p)" + +constdefs \ :: "fm \ int \ num \ fm" + "\ p k t \ And (Dvd k t) (\\ p (t,k))" + +lemma \\: + assumes linp: "iszlfm p (real (x::int)#bs)" + and kpos: "real k > 0" + and tnb: "numbound0 t" + and tint: "isint t (real x#bs)" + and kdt: "k dvd floor (Inum (b'#bs) t)" + shows "Ifm (real x#bs) (\\ p (t,k)) = + (Ifm ((real ((floor (Inum (b'#bs) t)) div k))#bs) p)" + (is "?I (real x) (?s p) = (?I (real ((floor (?N b' t)) div k)) p)" is "_ = (?I ?tk p)") +using linp kpos tnb +proof(induct p rule: \\.induct) + case (3 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (Eq (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k = 0)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (Eq (CN 0 c e)))" using nonzero_eq_divide_eq[OF knz', where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (4 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (NEq (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \ 0)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (NEq (CN 0 c e)))" using nonzero_eq_divide_eq[OF knz', where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (5 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (Lt (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k < 0)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (Lt (CN 0 c e)))" using pos_less_divide_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (6 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (Le (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \ 0)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (Le (CN 0 c e)))" using pos_le_divide_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (7 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (Gt (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k > 0)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (Gt (CN 0 c e)))" using pos_divide_less_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (8 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (Ge (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \ 0)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (Ge (CN 0 c e)))" using pos_divide_le_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (9 i c e) from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (Dvd i (CN 0 c e))) = (real i * real k rdvd (real c * (?N (real x) t / real k) + ?N (real x) e)* real k)" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (Dvd i (CN 0 c e)))" using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +next + case (10 i c e) from prems have cp: "c > 0" and nb: "numbound0 e" by auto + {assume kdc: "k dvd c" + from kpos have knz: "k\0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } + moreover + {assume "\ k dvd c" + from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp + from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp + from prems have "?I (real x) (?s (NDvd i (CN 0 c e))) = (\ (real i * real k rdvd (real c * (?N (real x) t / real k) + ?N (real x) e)* real k))" + using real_of_int_div[OF knz kdt] + numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) + also have "\ = (?I ?tk (NDvd i (CN 0 c e)))" using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] + numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] + by (simp add: ti) + finally have ?case . } + ultimately show ?case by blast +qed (simp_all add: nth_pos2 bound0_I[where bs="bs" and b="real ((floor (?N b' t)) div k)" and b'="real x"] numbound0_I[where bs="bs" and b="real ((floor (?N b' t)) div k)" and b'="real x"]) + + +lemma a\: + assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "real k > 0" + shows "Ifm (real (x*k)#bs) (a\ p k) = Ifm (real x#bs) p" (is "?I (x*k) (?f p k) = ?I x p") +using lp bound0_I[where bs="bs" and b="real (x*k)" and b'="real x"] numbound0_I[where bs="bs" and b="real (x*k)" and b'="real x"] +proof(induct p rule: a\.induct) + case (3 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] nonzero_eq_divide_eq[OF knz', where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} + ultimately show ?case by blast +next + case (4 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] nonzero_eq_divide_eq[OF knz', where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} + ultimately show ?case by blast +next + case (5 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_less_divide_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} + ultimately show ?case by blast +next + case (6 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_le_divide_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} + ultimately show ?case by blast +next + case (7 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_divide_less_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} + ultimately show ?case by blast +next + case (8 c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_divide_le_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} + ultimately show ?case by blast +next + case (9 i c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume "\ k dvd c" + hence "Ifm (real (x*k)#bs) (a\ (Dvd i (CN 0 c e)) k) = + (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k)" + using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] + by (simp add: algebra_simps) + also have "\ = (Ifm (real x#bs) (Dvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"]) + finally have ?case . } + ultimately show ?case by blast +next + case (10 i c e) + from prems have cp: "c > 0" and nb: "numbound0 e" by auto + from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp + {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } + moreover + {assume "\ k dvd c" + hence "Ifm (real (x*k)#bs) (a\ (NDvd i (CN 0 c e)) k) = + (\ (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k))" + using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] + by (simp add: algebra_simps) + also have "\ = (Ifm (real x#bs) (NDvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"]) + finally have ?case . } + ultimately show ?case by blast +qed (simp_all add: nth_pos2) + +lemma a\_ex: + assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0" + shows "(\ (x::int). real k rdvd real x \ Ifm (real x#bs) (a\ p k)) = + (\ (x::int). Ifm (real x#bs) p)" (is "(\ x. ?D x \ ?P' x) = (\ x. ?P x)") +proof- + have "(\ x. ?D x \ ?P' x) = (\ x. k dvd x \ ?P' x)" using int_rdvd_iff by simp + also have "\ = (\x. ?P' (x*k))" using unity_coeff_ex[where P="?P'" and l="k", simplified] + by (simp add: algebra_simps) + also have "\ = (\ x. ?P x)" using a\ iszlfm_gen[OF lp] kp by auto + finally show ?thesis . +qed + +lemma \\': assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0" and nb: "numbound0 t" + shows "Ifm (real x#bs) (\\ p (t,k)) = Ifm ((Inum (real x#bs) t)#bs) (a\ p k)" +using lp +by(induct p rule: \\.induct, simp_all add: + numbound0_I[OF nb, where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] + numbound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] + bound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] nth_pos2 cong: imp_cong) + +lemma \\_nb: assumes lp:"iszlfm p (a#bs)" and nb: "numbound0 t" + shows "bound0 (\\ p (t,k))" + using lp + by (induct p rule: iszlfm.induct, auto simp add: nb) + +lemma \_l: + assumes lp: "iszlfm p (real (i::int)#bs)" + shows "\ (b,k) \ set (\ p). k >0 \ numbound0 b \ isint b (real i#bs)" +using lp by (induct p rule: \.induct, auto simp add: isint_sub isint_neg) + +lemma \\_l: + assumes lp: "iszlfm p (real (i::int)#bs)" + shows "\ (b,k) \ set (\\ p). k >0 \ numbound0 b \ isint b (real i#bs)" +using lp isint_add [OF isint_c[where j="- 1"],where bs="real i#bs"] + by (induct p rule: \\.induct, auto) + +lemma zminusinf_\: + assumes lp: "iszlfm p (real (i::int)#bs)" + and nmi: "\ (Ifm (real i#bs) (minusinf p))" (is "\ (Ifm (real i#bs) (?M p))") + and ex: "Ifm (real i#bs) p" (is "?I i p") + shows "\ (e,c) \ set (\ p). real (c*i) > Inum (real i#bs) e" (is "\ (e,c) \ ?R p. real (c*i) > ?N i e") + using lp nmi ex +by (induct p rule: minusinf.induct, auto) + + +lemma \_And: "Ifm bs (\ (And p q) k t) = Ifm bs (And (\ p k t) (\ q k t))" +using \_def by auto +lemma \_Or: "Ifm bs (\ (Or p q) k t) = Ifm bs (Or (\ p k t) (\ q k t))" +using \_def by auto + +lemma \: assumes lp: "iszlfm p (real (i::int) #bs)" + and pi: "Ifm (real i#bs) p" + and d: "d\ p d" + and dp: "d > 0" + and nob: "\(e,c) \ set (\ p). \ j\ {1 .. c*d}. real (c*i) \ Inum (real i#bs) e + real j" + (is "\(e,c) \ set (\ p). \ j\ {1 .. c*d}. _ \ ?N i e + _") + shows "Ifm (real(i - d)#bs) p" + using lp pi d nob +proof(induct p rule: iszlfm.induct) + case (3 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" + and pi: "real (c*i) = - 1 - ?N i e + real (1::int)" and nob: "\ j\ {1 .. c*d}. real (c*i) \ -1 - ?N i e + real j" + by simp+ + from mult_strict_left_mono[OF dp cp] have one:"1 \ {1 .. c*d}" by auto + from nob[rule_format, where j="1", OF one] pi show ?case by simp +next + case (4 c e) + hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" + and nob: "\ j\ {1 .. c*d}. real (c*i) \ - ?N i e + real j" + by simp+ + {assume "real (c*i) \ - ?N i e + real (c*d)" + with numbound0_I[OF nb, where bs="bs" and b="real i - real d" and b'="real i"] + have ?case by (simp add: algebra_simps)} + moreover + {assume pi: "real (c*i) = - ?N i e + real (c*d)" + from mult_strict_left_mono[OF dp cp] have d: "(c*d) \ {1 .. c*d}" by simp + from nob[rule_format, where j="c*d", OF d] pi have ?case by simp } + ultimately show ?case by blast +next + case (5 c e) hence cp: "c > 0" by simp + from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] + real_of_int_mult] + show ?case using prems dp + by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] + algebra_simps) +next + case (6 c e) hence cp: "c > 0" by simp + from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] + real_of_int_mult] + show ?case using prems dp + by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] + algebra_simps) +next + case (7 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" + and nob: "\ j\ {1 .. c*d}. real (c*i) \ - ?N i e + real j" + and pi: "real (c*i) + ?N i e > 0" and cp': "real c >0" + by simp+ + let ?fe = "floor (?N i e)" + from pi cp have th:"(real i +?N i e / real c)*real c > 0" by (simp add: algebra_simps) + from pi ei[simplified isint_iff] have "real (c*i + ?fe) > real (0::int)" by simp + hence pi': "c*i + ?fe > 0" by (simp only: real_of_int_less_iff[symmetric]) + have "real (c*i) + ?N i e > real (c*d) \ real (c*i) + ?N i e \ real (c*d)" by auto + moreover + {assume "real (c*i) + ?N i e > real (c*d)" hence ?case + by (simp add: algebra_simps + numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} + moreover + {assume H:"real (c*i) + ?N i e \ real (c*d)" + with ei[simplified isint_iff] have "real (c*i + ?fe) \ real (c*d)" by simp + hence pid: "c*i + ?fe \ c*d" by (simp only: real_of_int_le_iff) + with pi' have "\ j1\ {1 .. c*d}. c*i + ?fe = j1" by auto + hence "\ j1\ {1 .. c*d}. real (c*i) = - ?N i e + real j1" + by (simp only: diff_def[symmetric] real_of_int_mult real_of_int_add real_of_int_inject[symmetric] ei[simplified isint_iff] algebra_simps) + with nob have ?case by blast } + ultimately show ?case by blast +next + case (8 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" + and nob: "\ j\ {1 .. c*d}. real (c*i) \ - 1 - ?N i e + real j" + and pi: "real (c*i) + ?N i e \ 0" and cp': "real c >0" + by simp+ + let ?fe = "floor (?N i e)" + from pi cp have th:"(real i +?N i e / real c)*real c \ 0" by (simp add: algebra_simps) + from pi ei[simplified isint_iff] have "real (c*i + ?fe) \ real (0::int)" by simp + hence pi': "c*i + 1 + ?fe \ 1" by (simp only: real_of_int_le_iff[symmetric]) + have "real (c*i) + ?N i e \ real (c*d) \ real (c*i) + ?N i e < real (c*d)" by auto + moreover + {assume "real (c*i) + ?N i e \ real (c*d)" hence ?case + by (simp add: algebra_simps + numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} + moreover + {assume H:"real (c*i) + ?N i e < real (c*d)" + with ei[simplified isint_iff] have "real (c*i + ?fe) < real (c*d)" by simp + hence pid: "c*i + 1 + ?fe \ c*d" by (simp only: real_of_int_le_iff) + with pi' have "\ j1\ {1 .. c*d}. c*i + 1+ ?fe = j1" by auto + hence "\ j1\ {1 .. c*d}. real (c*i) + 1= - ?N i e + real j1" + by (simp only: diff_def[symmetric] real_of_int_mult real_of_int_add real_of_int_inject[symmetric] ei[simplified isint_iff] algebra_simps real_of_one) + hence "\ j1\ {1 .. c*d}. real (c*i) = (- ?N i e + real j1) - 1" + by (simp only: algebra_simps diff_def[symmetric]) + hence "\ j1\ {1 .. c*d}. real (c*i) = - 1 - ?N i e + real j1" + by (simp only: add_ac diff_def) + with nob have ?case by blast } + ultimately show ?case by blast +next + case (9 j c e) hence p: "real j rdvd real (c*i) + ?N i e" (is "?p x") and cp: "c > 0" and bn:"numbound0 e" by simp+ + let ?e = "Inum (real i # bs) e" + from prems have "isint e (real i #bs)" by simp + hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real i)#bs"] numbound0_I[OF bn,where b="real i" and b'="real i" and bs="bs"] + by (simp add: isint_iff) + from prems have id: "j dvd d" by simp + from ie[symmetric] have "?p i = (real j rdvd real (c*i+ floor ?e))" by simp + also have "\ = (j dvd c*i + floor ?e)" + using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp + also have "\ = (j dvd c*i - c*d + floor ?e)" + using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp + also have "\ = (real j rdvd real (c*i - c*d + floor ?e))" + using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified] + ie by simp + also have "\ = (real j rdvd real (c*(i - d)) + ?e)" + using ie by (simp add:algebra_simps) + finally show ?case + using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p + by (simp add: algebra_simps) +next + case (10 j c e) hence p: "\ (real j rdvd real (c*i) + ?N i e)" (is "?p x") and cp: "c > 0" and bn:"numbound0 e" by simp+ + let ?e = "Inum (real i # bs) e" + from prems have "isint e (real i #bs)" by simp + hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real i)#bs"] numbound0_I[OF bn,where b="real i" and b'="real i" and bs="bs"] + by (simp add: isint_iff) + from prems have id: "j dvd d" by simp + from ie[symmetric] have "?p i = (\ (real j rdvd real (c*i+ floor ?e)))" by simp + also have "\ = Not (j dvd c*i + floor ?e)" + using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp + also have "\ = Not (j dvd c*i - c*d + floor ?e)" + using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp + also have "\ = Not (real j rdvd real (c*i - c*d + floor ?e))" + using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified] + ie by simp + also have "\ = Not (real j rdvd real (c*(i - d)) + ?e)" + using ie by (simp add:algebra_simps) + finally show ?case + using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p + by (simp add: algebra_simps) +qed(auto simp add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] nth_pos2) + +lemma \_nb: assumes lp: "iszlfm p (a#bs)" and nb: "numbound0 t" + shows "bound0 (\ p k t)" + using \\_nb[OF lp nb] nb by (simp add: \_def) + +lemma \': assumes lp: "iszlfm p (a #bs)" + and d: "d\ p d" + and dp: "d > 0" + shows "\ x. \(\ (e,c) \ set(\ p). \(j::int) \ {1 .. c*d}. Ifm (a #bs) (\ p c (Add e (C j)))) \ Ifm (real x#bs) p \ Ifm (real (x - d)#bs) p" (is "\ x. ?b x \ ?P x \ ?P (x - d)") +proof(clarify) + fix x + assume nob1:"?b x" and px: "?P x" + from iszlfm_gen[OF lp, rule_format, where y="real x"] have lp': "iszlfm p (real x#bs)". + have nob: "\(e, c)\set (\ p). \j\{1..c * d}. real (c * x) \ Inum (real x # bs) e + real j" + proof(clarify) + fix e c j assume ecR: "(e,c) \ set (\ p)" and jD: "j\ {1 .. c*d}" + and cx: "real (c*x) = Inum (real x#bs) e + real j" + let ?e = "Inum (real x#bs) e" + let ?fe = "floor ?e" + from \_l[OF lp'] ecR have ei:"isint e (real x#bs)" and cp:"c>0" and nb:"numbound0 e" + by auto + from numbound0_gen [OF nb ei, rule_format,where y="a"] have "isint e (a#bs)" . + from cx ei[simplified isint_iff] have "real (c*x) = real (?fe + j)" by simp + hence cx: "c*x = ?fe + j" by (simp only: real_of_int_inject) + hence cdej:"c dvd ?fe + j" by (simp add: dvd_def) (rule_tac x="x" in exI, simp) + hence "real c rdvd real (?fe + j)" by (simp only: int_rdvd_iff) + hence rcdej: "real c rdvd ?e + real j" by (simp add: ei[simplified isint_iff]) + from cx have "(c*x) div c = (?fe + j) div c" by simp + with cp have "x = (?fe + j) div c" by simp + with px have th: "?P ((?fe + j) div c)" by auto + from cp have cp': "real c > 0" by simp + from cdej have cdej': "c dvd floor (Inum (real x#bs) (Add e (C j)))" by simp + from nb have nb': "numbound0 (Add e (C j))" by simp + have ji: "isint (C j) (real x#bs)" by (simp add: isint_def) + from isint_add[OF ei ji] have ei':"isint (Add e (C j)) (real x#bs)" . + from th \\[where b'="real x", OF lp' cp' nb' ei' cdej',symmetric] + have "Ifm (real x#bs) (\\ p (Add e (C j), c))" by simp + with rcdej have th: "Ifm (real x#bs) (\ p c (Add e (C j)))" by (simp add: \_def) + from th bound0_I[OF \_nb[OF lp nb', where k="c"],where bs="bs" and b="real x" and b'="a"] + have "Ifm (a#bs) (\ p c (Add e (C j)))" by blast + with ecR jD nob1 show "False" by blast + qed + from \[OF lp' px d dp nob] show "?P (x -d )" . +qed + + +lemma rl_thm: + assumes lp: "iszlfm p (real (i::int)#bs)" + shows "(\ (x::int). Ifm (real x#bs) p) = ((\ j\ {1 .. \ p}. Ifm (real j#bs) (minusinf p)) \ (\ (e,c) \ set (\ p). \ j\ {1 .. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j)))))" + (is "(\(x::int). ?P x) = ((\ j\ {1.. \ p}. ?MP j)\(\ (e,c) \ ?R. \ j\ _. ?SP c e j))" + is "?lhs = (?MD \ ?RD)" is "?lhs = ?rhs") +proof- + let ?d= "\ p" + from \[OF lp] have d:"d\ p ?d" and dp: "?d > 0" by auto + { assume H:"?MD" hence th:"\ (x::int). ?MP x" by blast + from H minusinf_ex[OF lp th] have ?thesis by blast} + moreover + { fix e c j assume exR:"(e,c) \ ?R" and jD:"j\ {1 .. c*?d}" and spx:"?SP c e j" + from exR \_l[OF lp] have nb: "numbound0 e" and ei:"isint e (real i#bs)" and cp: "c > 0" + by auto + have "isint (C j) (real i#bs)" by (simp add: isint_iff) + with isint_add[OF numbound0_gen[OF nb ei,rule_format, where y="real i"]] + have eji:"isint (Add e (C j)) (real i#bs)" by simp + from nb have nb': "numbound0 (Add e (C j))" by simp + from spx bound0_I[OF \_nb[OF lp nb', where k="c"], where bs="bs" and b="a" and b'="real i"] + have spx': "Ifm (real i # bs) (\ p c (Add e (C j)))" by blast + from spx' have rcdej:"real c rdvd (Inum (real i#bs) (Add e (C j)))" + and sr:"Ifm (real i#bs) (\\ p (Add e (C j),c))" by (simp add: \_def)+ + from rcdej eji[simplified isint_iff] + have "real c rdvd real (floor (Inum (real i#bs) (Add e (C j))))" by simp + hence cdej:"c dvd floor (Inum (real i#bs) (Add e (C j)))" by (simp only: int_rdvd_iff) + from cp have cp': "real c > 0" by simp + from \\[OF lp cp' nb' eji cdej] spx' have "?P (\Inum (real i # bs) (Add e (C j))\ div c)" + by (simp add: \_def) + hence ?lhs by blast + with exR jD spx have ?thesis by blast} + moreover + { fix x assume px: "?P x" and nob: "\ ?RD" + from iszlfm_gen [OF lp,rule_format, where y="a"] have lp':"iszlfm p (a#bs)" . + from \'[OF lp' d dp, rule_format, OF nob] have th:"\ x. ?P x \ ?P (x - ?d)" by blast + from minusinf_inf[OF lp] obtain z where z:"\ x 0" by arith + from decr_lemma[OF dp,where x="x" and z="z"] + decr_mult_lemma[OF dp th zp, rule_format, OF px] z have th:"\ x. ?MP x" by auto + with minusinf_bex[OF lp] px nob have ?thesis by blast} + ultimately show ?thesis by blast +qed + +lemma mirror_\\: assumes lp: "iszlfm p (a#bs)" + shows "(\ (t,k). (Inum (a#bs) t, k)) ` set (\\ p) = (\ (t,k). (Inum (a#bs) t,k)) ` set (\ (mirror p))" +using lp +by (induct p rule: mirror.induct, simp_all add: split_def image_Un ) + +text {* The @{text "\"} part*} + +text{* Linearity for fm where Bound 0 ranges over @{text "\"}*} +consts + isrlfm :: "fm \ bool" (* Linearity test for fm *) +recdef isrlfm "measure size" + "isrlfm (And p q) = (isrlfm p \ isrlfm q)" + "isrlfm (Or p q) = (isrlfm p \ isrlfm q)" + "isrlfm (Eq (CN 0 c e)) = (c>0 \ numbound0 e)" + "isrlfm (NEq (CN 0 c e)) = (c>0 \ numbound0 e)" + "isrlfm (Lt (CN 0 c e)) = (c>0 \ numbound0 e)" + "isrlfm (Le (CN 0 c e)) = (c>0 \ numbound0 e)" + "isrlfm (Gt (CN 0 c e)) = (c>0 \ numbound0 e)" + "isrlfm (Ge (CN 0 c e)) = (c>0 \ numbound0 e)" + "isrlfm p = (isatom p \ (bound0 p))" + +constdefs fp :: "fm \ int \ num \ int \ fm" + "fp p n s j \ (if n > 0 then + (And p (And (Ge (CN 0 n (Sub s (Add (Floor s) (C j))))) + (Lt (CN 0 n (Sub s (Add (Floor s) (C (j+1)))))))) + else + (And p (And (Le (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C j))))) + (Gt (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C (j + 1)))))))))" + + (* splits the bounded from the unbounded part*) +consts rsplit0 :: "num \ (fm \ int \ num) list" +recdef rsplit0 "measure num_size" + "rsplit0 (Bound 0) = [(T,1,C 0)]" + "rsplit0 (Add a b) = (let acs = rsplit0 a ; bcs = rsplit0 b + in map (\ ((p,n,t),(q,m,s)). (And p q, n+m, Add t s)) [(a,b). a\acs,b\bcs])" + "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))" + "rsplit0 (Neg a) = map (\ (p,n,s). (p,-n,Neg s)) (rsplit0 a)" + "rsplit0 (Floor a) = foldl (op @) [] (map + (\ (p,n,s). if n=0 then [(p,0,Floor s)] + else (map (\ j. (fp p n s j, 0, Add (Floor s) (C j))) (if n > 0 then iupt (0,n) else iupt(n,0)))) + (rsplit0 a))" + "rsplit0 (CN 0 c a) = map (\ (p,n,s). (p,n+c,s)) (rsplit0 a)" + "rsplit0 (CN m c a) = map (\ (p,n,s). (p,n,CN m c s)) (rsplit0 a)" + "rsplit0 (CF c t s) = rsplit0 (Add (Mul c (Floor t)) s)" + "rsplit0 (Mul c a) = map (\ (p,n,s). (p,c*n,Mul c s)) (rsplit0 a)" + "rsplit0 t = [(T,0,t)]" + +lemma not_rl[simp]: "isrlfm p \ isrlfm (not p)" + by (induct p rule: isrlfm.induct, auto) +lemma conj_rl[simp]: "isrlfm p \ isrlfm q \ isrlfm (conj p q)" + using conj_def by (cases p, auto) +lemma disj_rl[simp]: "isrlfm p \ isrlfm q \ isrlfm (disj p q)" + using disj_def by (cases p, auto) + + +lemma rsplit0_cs: + shows "\ (p,n,s) \ set (rsplit0 t). + (Ifm (x#bs) p \ (Inum (x#bs) t = Inum (x#bs) (CN 0 n s))) \ numbound0 s \ isrlfm p" + (is "\ (p,n,s) \ ?SS t. (?I p \ ?N t = ?N (CN 0 n s)) \ _ \ _ ") +proof(induct t rule: rsplit0.induct) + case (5 a) + let ?p = "\ (p,n,s) j. fp p n s j" + let ?f = "(\ (p,n,s) j. (?p (p,n,s) j, (0::int),Add (Floor s) (C j)))" + let ?J = "\ n. if n>0 then iupt (0,n) else iupt (n,0)" + let ?ff=" (\ (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))" + have int_cases: "\ (i::int). i= 0 \ i < 0 \ i > 0" by arith + have U1: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) = + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)]))" by auto + have U2': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n>0}. + ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))" by auto + hence U2: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) = + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). + set (map (?f(p,n,s)) (iupt(0,n)))))" + proof- + fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g + assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" + thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" + by (auto simp add: split_def) + qed + have U3': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n<0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(n,0))" + by auto + hence U3: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))) = + (UNION {(p,n,s). (p,n,s)\ ?SS a\n<0} (\(p,n,s). set (map (?f(p,n,s)) (iupt(n,0)))))" + proof- + fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g + assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" + thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" + by (auto simp add: split_def) + qed + have "?SS (Floor a) = UNION (?SS a) (\x. set (?ff x))" + by (auto simp add: foldl_conv_concat) + also have "\ = UNION (?SS a) (\ (p,n,s). set (?ff (p,n,s)))" by auto + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))))" + using int_cases[rule_format] by blast + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)])) Un + (UNION {(p,n,s). (p,n,s)\ ?SS a\n>0} (\(p,n,s). set(map(?f(p,n,s)) (iupt(0,n))))) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). + set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3) + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). (?f(p,n,s)) ` {0 .. n})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). (?f(p,n,s)) ` {n .. 0})))" + by (simp only: set_map iupt_set set.simps) + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast + finally + have FS: "?SS (Floor a) = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast + show ?case + proof(simp only: FS, clarsimp simp del: Ifm.simps Inum.simps, -) + fix p n s + let ?ths = "(?I p \ (?N (Floor a) = ?N (CN 0 n s))) \ numbound0 s \ isrlfm p" + assume "(\ba. (p, 0, ba) \ set (rsplit0 a) \ n = 0 \ s = Floor ba) \ + (\ab ac ba. + (ab, ac, ba) \ set (rsplit0 a) \ + 0 < ac \ + (\j. p = fp ab ac ba j \ + n = 0 \ s = Add (Floor ba) (C j) \ 0 \ j \ j \ ac)) \ + (\ab ac ba. + (ab, ac, ba) \ set (rsplit0 a) \ + ac < 0 \ + (\j. p = fp ab ac ba j \ + n = 0 \ s = Add (Floor ba) (C j) \ ac \ j \ j \ 0))" + moreover + {fix s' + assume "(p, 0, s') \ ?SS a" and "n = 0" and "s = Floor s'" + hence ?ths using prems by auto} + moreover + { fix p' n' s' j + assume pns: "(p', n', s') \ ?SS a" + and np: "0 < n'" + and p_def: "p = ?p (p',n',s') j" + and n0: "n = 0" + and s_def: "s = (Add (Floor s') (C j))" + and jp: "0 \ j" and jn: "j \ n'" + from prems pns have H:"(Ifm ((x\real) # (bs\real list)) p' \ + Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \ + numbound0 s' \ isrlfm p'" by blast + hence nb: "numbound0 s'" by simp + from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numsub_nb) + let ?nxs = "CN 0 n' s'" + let ?l = "floor (?N s') + j" + from H + have "?I (?p (p',n',s') j) \ + (((?N ?nxs \ real ?l) \ (?N ?nxs < real (?l + 1))) \ (?N a = ?N ?nxs ))" + by (simp add: fp_def np algebra_simps numsub numadd numfloor) + also have "\ \ ((floor (?N ?nxs) = ?l) \ (?N a = ?N ?nxs ))" + using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp + moreover + have "\ \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" by simp + ultimately have "?I (?p (p',n',s') j) \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" + by blast + with s_def n0 p_def nb nf have ?ths by auto} + moreover + {fix p' n' s' j + assume pns: "(p', n', s') \ ?SS a" + and np: "n' < 0" + and p_def: "p = ?p (p',n',s') j" + and n0: "n = 0" + and s_def: "s = (Add (Floor s') (C j))" + and jp: "n' \ j" and jn: "j \ 0" + from prems pns have H:"(Ifm ((x\real) # (bs\real list)) p' \ + Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \ + numbound0 s' \ isrlfm p'" by blast + hence nb: "numbound0 s'" by simp + from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numneg_nb) + let ?nxs = "CN 0 n' s'" + let ?l = "floor (?N s') + j" + from H + have "?I (?p (p',n',s') j) \ + (((?N ?nxs \ real ?l) \ (?N ?nxs < real (?l + 1))) \ (?N a = ?N ?nxs ))" + by (simp add: np fp_def algebra_simps numneg numfloor numadd numsub) + also have "\ \ ((floor (?N ?nxs) = ?l) \ (?N a = ?N ?nxs ))" + using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp + moreover + have "\ \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" by simp + ultimately have "?I (?p (p',n',s') j) \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" + by blast + with s_def n0 p_def nb nf have ?ths by auto} + ultimately show ?ths by auto + qed +next + case (3 a b) then show ?case + apply auto + apply (erule_tac x = "(aa, aaa, ba)" in ballE) apply simp_all + apply (erule_tac x = "(ab, ac, baa)" in ballE) apply simp_all + done +qed (auto simp add: Let_def split_def algebra_simps conj_rl) + +lemma real_in_int_intervals: + assumes xb: "real m \ x \ x < real ((n::int) + 1)" + shows "\ j\ {m.. n}. real j \ x \ x < real (j+1)" (is "\ j\ ?N. ?P j") +by (rule bexI[where P="?P" and x="floor x" and A="?N"]) +(auto simp add: floor_less_eq[where x="x" and a="n+1", simplified] xb[simplified] floor_mono2[where x="real m" and y="x", OF conjunct1[OF xb], simplified floor_real_of_int[where n="m"]]) + +lemma rsplit0_complete: + assumes xp:"0 \ x" and x1:"x < 1" + shows "\ (p,n,s) \ set (rsplit0 t). Ifm (x#bs) p" (is "\ (p,n,s) \ ?SS t. ?I p") +proof(induct t rule: rsplit0.induct) + case (2 a b) + from prems have "\ (pa,na,sa) \ ?SS a. ?I pa" by auto + then obtain "pa" "na" "sa" where pa: "(pa,na,sa)\ ?SS a \ ?I pa" by blast + from prems have "\ (pb,nb,sb) \ ?SS b. ?I pb" by auto + then obtain "pb" "nb" "sb" where pb: "(pb,nb,sb)\ ?SS b \ ?I pb" by blast + from pa pb have th: "((pa,na,sa),(pb,nb,sb)) \ set[(x,y). x\rsplit0 a, y\rsplit0 b]" + by (auto) + let ?f="(\ ((p,n,t),(q,m,s)). (And p q, n+m, Add t s))" + from imageI[OF th, where f="?f"] have "?f ((pa,na,sa),(pb,nb,sb)) \ ?SS (Add a b)" + by (simp add: Let_def) + hence "(And pa pb, na +nb, Add sa sb) \ ?SS (Add a b)" by simp + moreover from pa pb have "?I (And pa pb)" by simp + ultimately show ?case by blast +next + case (5 a) + let ?p = "\ (p,n,s) j. fp p n s j" + let ?f = "(\ (p,n,s) j. (?p (p,n,s) j, (0::int),(Add (Floor s) (C j))))" + let ?J = "\ n. if n>0 then iupt (0,n) else iupt (n,0)" + let ?ff=" (\ (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))" + have int_cases: "\ (i::int). i= 0 \ i < 0 \ i > 0" by arith + have U1: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)]))" by auto + have U2': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n>0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))" + by auto + hence U2: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(0,n)))))" + proof- + fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g + assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" + thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" + by (auto simp add: split_def) + qed + have U3': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n<0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(n,0))" + by auto + hence U3: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(n,0)))))" + proof- + fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g + assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" + thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" + by (auto simp add: split_def) + qed + + have "?SS (Floor a) = UNION (?SS a) (\x. set (?ff x))" by (auto simp add: foldl_conv_concat) + also have "\ = UNION (?SS a) (\ (p,n,s). set (?ff (p,n,s)))" by auto + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))))" + using int_cases[rule_format] by blast + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)])) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(0,n))))) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3) + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). (?f(p,n,s)) ` {0 .. n})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). (?f(p,n,s)) ` {n .. 0})))" + by (simp only: set_map iupt_set set.simps) + also have "\ = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast + finally + have FS: "?SS (Floor a) = + ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un + (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast + from prems have "\ (p,n,s) \ ?SS a. ?I p" by auto + then obtain "p" "n" "s" where pns: "(p,n,s) \ ?SS a \ ?I p" by blast + let ?N = "\ t. Inum (x#bs) t" + from rsplit0_cs[rule_format] pns have ans:"(?N a = ?N (CN 0 n s)) \ numbound0 s \ isrlfm p" + by auto + + have "n=0 \ n >0 \ n <0" by arith + moreover {assume "n=0" hence ?case using pns by (simp only: FS) auto } + moreover + { + assume np: "n > 0" + from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) \ ?N s" by simp + also from mult_left_mono[OF xp] np have "?N s \ real n * x + ?N s" by simp + finally have "?N (Floor s) \ real n * x + ?N s" . + moreover + {from mult_strict_left_mono[OF x1] np + have "real n *x + ?N s < real n + ?N s" by simp + also from real_of_int_floor_add_one_gt[where r="?N s"] + have "\ < real n + ?N (Floor s) + 1" by simp + finally have "real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp} + ultimately have "?N (Floor s) \ real n *x + ?N s\ real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp + hence th: "0 \ real n *x + ?N s - ?N (Floor s) \ real n *x + ?N s - ?N (Floor s) < real (n+1)" by simp + from real_in_int_intervals th have "\ j\ {0 .. n}. real j \ real n *x + ?N s - ?N (Floor s)\ real n *x + ?N s - ?N (Floor s) < real (j+1)" by simp + + hence "\ j\ {0 .. n}. 0 \ real n *x + ?N s - ?N (Floor s) - real j \ real n *x + ?N s - ?N (Floor s) - real (j+1) < 0" + by(simp only: myl[rule_format, where b="real n * x + Inum (x # bs) s - Inum (x # bs) (Floor s)"] less_iff_diff_less_0[where a="real n *x + ?N s - ?N (Floor s)"]) + hence "\ j\ {0.. n}. ?I (?p (p,n,s) j)" + using pns by (simp add: fp_def np algebra_simps numsub numadd) + then obtain "j" where j_def: "j\ {0 .. n} \ ?I (?p (p,n,s) j)" by blast + hence "\x \ {?p (p,n,s) j |j. 0\ j \ j \ n }. ?I x" by auto + hence ?case using pns + by (simp only: FS,simp add: bex_Un) + (rule disjI2, rule disjI1,rule exI [where x="p"], + rule exI [where x="n"],rule exI [where x="s"],simp_all add: np) + } + moreover + { assume nn: "n < 0" hence np: "-n >0" by simp + from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) + 1 > ?N s" by simp + moreover from mult_left_mono_neg[OF xp] nn have "?N s \ real n * x + ?N s" by simp + ultimately have "?N (Floor s) + 1 > real n * x + ?N s" by arith + moreover + {from mult_strict_left_mono_neg[OF x1, where c="real n"] nn + have "real n *x + ?N s \ real n + ?N s" by simp + moreover from real_of_int_floor_le[where r="?N s"] have "real n + ?N s \ real n + ?N (Floor s)" by simp + ultimately have "real n *x + ?N s \ ?N (Floor s) + real n" + by (simp only: algebra_simps)} + ultimately have "?N (Floor s) + real n \ real n *x + ?N s\ real n *x + ?N s < ?N (Floor s) + real (1::int)" by simp + hence th: "real n \ real n *x + ?N s - ?N (Floor s) \ real n *x + ?N s - ?N (Floor s) < real (1::int)" by simp + have th1: "\ (a::real). (- a > 0) = (a < 0)" by auto + have th2: "\ (a::real). (0 \ - a) = (a \ 0)" by auto + from real_in_int_intervals th have "\ j\ {n .. 0}. real j \ real n *x + ?N s - ?N (Floor s)\ real n *x + ?N s - ?N (Floor s) < real (j+1)" by simp + + hence "\ j\ {n .. 0}. 0 \ real n *x + ?N s - ?N (Floor s) - real j \ real n *x + ?N s - ?N (Floor s) - real (j+1) < 0" + by(simp only: myl[rule_format, where b="real n * x + Inum (x # bs) s - Inum (x # bs) (Floor s)"] less_iff_diff_less_0[where a="real n *x + ?N s - ?N (Floor s)"]) + hence "\ j\ {n .. 0}. 0 \ - (real n *x + ?N s - ?N (Floor s) - real j) \ - (real n *x + ?N s - ?N (Floor s) - real (j+1)) > 0" by (simp only: th1[rule_format] th2[rule_format]) + hence "\ j\ {n.. 0}. ?I (?p (p,n,s) j)" + using pns by (simp add: fp_def nn diff_def add_ac mult_ac numfloor numadd numneg + del: diff_less_0_iff_less diff_le_0_iff_le) + then obtain "j" where j_def: "j\ {n .. 0} \ ?I (?p (p,n,s) j)" by blast + hence "\x \ {?p (p,n,s) j |j. n\ j \ j \ 0 }. ?I x" by auto + hence ?case using pns + by (simp only: FS,simp add: bex_Un) + (rule disjI2, rule disjI2,rule exI [where x="p"], + rule exI [where x="n"],rule exI [where x="s"],simp_all add: nn) + } + ultimately show ?case by blast +qed (auto simp add: Let_def split_def) + + (* Linearize a formula where Bound 0 ranges over [0,1) *) + +constdefs rsplit :: "(int \ num \ fm) \ num \ fm" + "rsplit f a \ foldr disj (map (\ (\, n, s). conj \ (f n s)) (rsplit0 a)) F" + +lemma foldr_disj_map: "Ifm bs (foldr disj (map f xs) F) = (\ x \ set xs. Ifm bs (f x))" +by(induct xs, simp_all) + +lemma foldr_conj_map: "Ifm bs (foldr conj (map f xs) T) = (\ x \ set xs. Ifm bs (f x))" +by(induct xs, simp_all) + +lemma foldr_disj_map_rlfm: + assumes lf: "\ n s. numbound0 s \ isrlfm (f n s)" + and \: "\ (\,n,s) \ set xs. numbound0 s \ isrlfm \" + shows "isrlfm (foldr disj (map (\ (\, n, s). conj \ (f n s)) xs) F)" +using lf \ by (induct xs, auto) + +lemma rsplit_ex: "Ifm bs (rsplit f a) = (\ (\,n,s) \ set (rsplit0 a). Ifm bs (conj \ (f n s)))" +using foldr_disj_map[where xs="rsplit0 a"] rsplit_def by (simp add: split_def) + +lemma rsplit_l: assumes lf: "\ n s. numbound0 s \ isrlfm (f n s)" + shows "isrlfm (rsplit f a)" +proof- + from rsplit0_cs[where t="a"] have th: "\ (\,n,s) \ set (rsplit0 a). numbound0 s \ isrlfm \" by blast + from foldr_disj_map_rlfm[OF lf th] rsplit_def show ?thesis by simp +qed + +lemma rsplit: + assumes xp: "x \ 0" and x1: "x < 1" + and f: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ (Ifm (x#bs) (f n s) = Ifm (x#bs) (g a))" + shows "Ifm (x#bs) (rsplit f a) = Ifm (x#bs) (g a)" +proof(auto) + let ?I = "\x p. Ifm (x#bs) p" + let ?N = "\ x t. Inum (x#bs) t" + assume "?I x (rsplit f a)" + hence "\ (\,n,s) \ set (rsplit0 a). ?I x (And \ (f n s))" using rsplit_ex by simp + then obtain "\" "n" "s" where fnsS:"(\,n,s) \ set (rsplit0 a)" and "?I x (And \ (f n s))" by blast + hence \: "?I x \" and fns: "?I x (f n s)" by auto + from rsplit0_cs[where t="a" and bs="bs" and x="x", rule_format, OF fnsS] \ + have th: "(?N x a = ?N x (CN 0 n s)) \ numbound0 s" by auto + from f[rule_format, OF th] fns show "?I x (g a)" by simp +next + let ?I = "\x p. Ifm (x#bs) p" + let ?N = "\ x t. Inum (x#bs) t" + assume ga: "?I x (g a)" + from rsplit0_complete[OF xp x1, where bs="bs" and t="a"] + obtain "\" "n" "s" where fnsS:"(\,n,s) \ set (rsplit0 a)" and fx: "?I x \" by blast + from rsplit0_cs[where t="a" and x="x" and bs="bs"] fnsS fx + have ans: "?N x a = ?N x (CN 0 n s)" and nb: "numbound0 s" by auto + with ga f have "?I x (f n s)" by auto + with rsplit_ex fnsS fx show "?I x (rsplit f a)" by auto +qed + +definition lt :: "int \ num \ fm" where + lt_def: "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) + else (Gt (CN 0 (-c) (Neg t))))" + +definition le :: "int \ num \ fm" where + le_def: "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) + else (Ge (CN 0 (-c) (Neg t))))" + +definition gt :: "int \ num \ fm" where + gt_def: "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) + else (Lt (CN 0 (-c) (Neg t))))" + +definition ge :: "int \ num \ fm" where + ge_def: "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) + else (Le (CN 0 (-c) (Neg t))))" + +definition eq :: "int \ num \ fm" where + eq_def: "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) + else (Eq (CN 0 (-c) (Neg t))))" + +definition neq :: "int \ num \ fm" where + neq_def: "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) + else (NEq (CN 0 (-c) (Neg t))))" + +lemma lt_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (lt n s) = Ifm (x#bs) (Lt a)" + (is "\ a n s . ?N a = ?N (CN 0 n s) \ _\ ?I (lt n s) = ?I (Lt a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" + show "?I (lt n s) = ?I (Lt a)" using H by (cases "n=0", (simp add: lt_def)) + (cases "n > 0", simp_all add: lt_def algebra_simps myless[rule_format, where b="0"]) +qed + +lemma lt_l: "isrlfm (rsplit lt a)" + by (rule rsplit_l[where f="lt" and a="a"], auto simp add: lt_def, + case_tac s, simp_all, case_tac "nat", simp_all) + +lemma le_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (le n s) = Ifm (x#bs) (Le a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (le n s) = ?I (Le a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" + show "?I (le n s) = ?I (Le a)" using H by (cases "n=0", (simp add: le_def)) + (cases "n > 0", simp_all add: le_def algebra_simps myl[rule_format, where b="0"]) +qed + +lemma le_l: "isrlfm (rsplit le a)" + by (rule rsplit_l[where f="le" and a="a"], auto simp add: le_def) +(case_tac s, simp_all, case_tac "nat",simp_all) + +lemma gt_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (gt n s) = Ifm (x#bs) (Gt a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (gt n s) = ?I (Gt a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" + show "?I (gt n s) = ?I (Gt a)" using H by (cases "n=0", (simp add: gt_def)) + (cases "n > 0", simp_all add: gt_def algebra_simps myless[rule_format, where b="0"]) +qed +lemma gt_l: "isrlfm (rsplit gt a)" + by (rule rsplit_l[where f="gt" and a="a"], auto simp add: gt_def) +(case_tac s, simp_all, case_tac "nat", simp_all) + +lemma ge_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (ge n s) = Ifm (x#bs) (Ge a)" (is "\ a n s . ?N a = ?N (CN 0 n s) \ _ \ ?I (ge n s) = ?I (Ge a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" + show "?I (ge n s) = ?I (Ge a)" using H by (cases "n=0", (simp add: ge_def)) + (cases "n > 0", simp_all add: ge_def algebra_simps myl[rule_format, where b="0"]) +qed +lemma ge_l: "isrlfm (rsplit ge a)" + by (rule rsplit_l[where f="ge" and a="a"], auto simp add: ge_def) +(case_tac s, simp_all, case_tac "nat", simp_all) + +lemma eq_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (eq n s) = Ifm (x#bs) (Eq a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (eq n s) = ?I (Eq a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" + show "?I (eq n s) = ?I (Eq a)" using H by (auto simp add: eq_def algebra_simps) +qed +lemma eq_l: "isrlfm (rsplit eq a)" + by (rule rsplit_l[where f="eq" and a="a"], auto simp add: eq_def) +(case_tac s, simp_all, case_tac"nat", simp_all) + +lemma neq_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (neq n s) = Ifm (x#bs) (NEq a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (neq n s) = ?I (NEq a)") +proof(clarify) + fix a n s bs + assume H: "?N a = ?N (CN 0 n s)" + show "?I (neq n s) = ?I (NEq a)" using H by (auto simp add: neq_def algebra_simps) +qed + +lemma neq_l: "isrlfm (rsplit neq a)" + by (rule rsplit_l[where f="neq" and a="a"], auto simp add: neq_def) +(case_tac s, simp_all, case_tac"nat", simp_all) + +lemma small_le: + assumes u0:"0 \ u" and u1: "u < 1" + shows "(-u \ real (n::int)) = (0 \ n)" +using u0 u1 by auto + +lemma small_lt: + assumes u0:"0 \ u" and u1: "u < 1" + shows "(real (n::int) < real (m::int) - u) = (n < m)" +using u0 u1 by auto + +lemma rdvd01_cs: + assumes up: "u \ 0" and u1: "u<1" and np: "real n > 0" + shows "(real (i::int) rdvd real (n::int) * u - s) = (\ j\ {0 .. n - 1}. real n * u = s - real (floor s) + real j \ real i rdvd real (j - floor s))" (is "?lhs = ?rhs") +proof- + let ?ss = "s - real (floor s)" + from real_of_int_floor_add_one_gt[where r="s", simplified myless[rule_format,where a="s"]] + real_of_int_floor_le[where r="s"] have ss0:"?ss \ 0" and ss1:"?ss < 1" + by (auto simp add: myl[rule_format, where b="s", symmetric] myless[rule_format, where a="?ss"]) + from np have n0: "real n \ 0" by simp + from mult_left_mono[OF up n0] mult_strict_left_mono[OF u1 np] + have nu0:"real n * u - s \ -s" and nun:"real n * u -s < real n - s" by auto + from int_rdvd_real[where i="i" and x="real (n::int) * u - s"] + have "real i rdvd real n * u - s = + (i dvd floor (real n * u -s) \ (real (floor (real n * u - s)) = real n * u - s ))" + (is "_ = (?DE)" is "_ = (?D \ ?E)") by simp + also have "\ = (?DE \ real(floor (real n * u - s) + floor s)\ -?ss + \ real(floor (real n * u - s) + floor s)< real n - ?ss)" (is "_=(?DE \real ?a \ _ \ real ?a < _)") + using nu0 nun by auto + also have "\ = (?DE \ ?a \ 0 \ ?a < n)" by(simp only: small_le[OF ss0 ss1] small_lt[OF ss0 ss1]) + also have "\ = (?DE \ (\ j\ {0 .. (n - 1)}. ?a = j))" by simp + also have "\ = (?DE \ (\ j\ {0 .. (n - 1)}. real (\real n * u - s\) = real j - real \s\ ))" + by (simp only: algebra_simps real_of_int_diff[symmetric] real_of_int_inject del: real_of_int_diff) + also have "\ = ((\ j\ {0 .. (n - 1)}. real n * u - s = real j - real \s\ \ real i rdvd real n * u - s))" using int_rdvd_iff[where i="i" and t="\real n * u - s\"] + by (auto cong: conj_cong) + also have "\ = ?rhs" by(simp cong: conj_cong) (simp add: algebra_simps ) + finally show ?thesis . +qed + +definition + DVDJ:: "int \ int \ num \ fm" +where + DVDJ_def: "DVDJ i n s = (foldr disj (map (\ j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (Dvd i (Sub (C j) (Floor (Neg s))))) (iupt(0,n - 1))) F)" + +definition + NDVDJ:: "int \ int \ num \ fm" +where + NDVDJ_def: "NDVDJ i n s = (foldr conj (map (\ j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (NDvd i (Sub (C j) (Floor (Neg s))))) (iupt(0,n - 1))) T)" + +lemma DVDJ_DVD: + assumes xp:"x\ 0" and x1: "x < 1" and np:"real n > 0" + shows "Ifm (x#bs) (DVDJ i n s) = Ifm (x#bs) (Dvd i (CN 0 n s))" +proof- + let ?f = "\ j. conj (Eq(CN 0 n (Add s (Sub(Floor (Neg s)) (C j))))) (Dvd i (Sub (C j) (Floor (Neg s))))" + let ?s= "Inum (x#bs) s" + from foldr_disj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"] + have "Ifm (x#bs) (DVDJ i n s) = (\ j\ {0 .. (n - 1)}. Ifm (x#bs) (?f j))" + by (simp add: iupt_set np DVDJ_def del: iupt.simps) + also have "\ = (\ j\ {0 .. (n - 1)}. real n * x = (- ?s) - real (floor (- ?s)) + real j \ real i rdvd real (j - floor (- ?s)))" by (simp add: algebra_simps diff_def[symmetric]) + also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] + have "\ = (real i rdvd real n * x - (-?s))" by simp + finally show ?thesis by simp +qed + +lemma NDVDJ_NDVD: + assumes xp:"x\ 0" and x1: "x < 1" and np:"real n > 0" + shows "Ifm (x#bs) (NDVDJ i n s) = Ifm (x#bs) (NDvd i (CN 0 n s))" +proof- + let ?f = "\ j. disj(NEq(CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (NDvd i (Sub (C j) (Floor(Neg s))))" + let ?s= "Inum (x#bs) s" + from foldr_conj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"] + have "Ifm (x#bs) (NDVDJ i n s) = (\ j\ {0 .. (n - 1)}. Ifm (x#bs) (?f j))" + by (simp add: iupt_set np NDVDJ_def del: iupt.simps) + also have "\ = (\ (\ j\ {0 .. (n - 1)}. real n * x = (- ?s) - real (floor (- ?s)) + real j \ real i rdvd real (j - floor (- ?s))))" by (simp add: algebra_simps diff_def[symmetric]) + also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] + have "\ = (\ (real i rdvd real n * x - (-?s)))" by simp + finally show ?thesis by simp +qed + +lemma foldr_disj_map_rlfm2: + assumes lf: "\ n . isrlfm (f n)" + shows "isrlfm (foldr disj (map f xs) F)" +using lf by (induct xs, auto) +lemma foldr_And_map_rlfm2: + assumes lf: "\ n . isrlfm (f n)" + shows "isrlfm (foldr conj (map f xs) T)" +using lf by (induct xs, auto) + +lemma DVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s" + shows "isrlfm (DVDJ i n s)" +proof- + let ?f="\j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) + (Dvd i (Sub (C j) (Floor (Neg s))))" + have th: "\ j. isrlfm (?f j)" using nb np by auto + from DVDJ_def foldr_disj_map_rlfm2[OF th] show ?thesis by simp +qed + +lemma NDVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s" + shows "isrlfm (NDVDJ i n s)" +proof- + let ?f="\j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) + (NDvd i (Sub (C j) (Floor (Neg s))))" + have th: "\ j. isrlfm (?f j)" using nb np by auto + from NDVDJ_def foldr_And_map_rlfm2[OF th] show ?thesis by auto +qed + +definition DVD :: "int \ int \ num \ fm" where + DVD_def: "DVD i c t = + (if i=0 then eq c t else + if c = 0 then (Dvd i t) else if c >0 then DVDJ (abs i) c t else DVDJ (abs i) (-c) (Neg t))" + +definition NDVD :: "int \ int \ num \ fm" where + "NDVD i c t = + (if i=0 then neq c t else + if c = 0 then (NDvd i t) else if c >0 then NDVDJ (abs i) c t else NDVDJ (abs i) (-c) (Neg t))" + +lemma DVD_mono: + assumes xp: "0\ x" and x1: "x < 1" + shows "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (DVD i n s) = Ifm (x#bs) (Dvd i a)" + (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (DVD i n s) = ?I (Dvd i a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s" + let ?th = "?I (DVD i n s) = ?I (Dvd i a)" + have "i=0 \ (i\0 \ n=0) \ (i\0 \ n < 0) \ (i\0 \ n > 0)" by arith + moreover {assume iz: "i=0" hence ?th using eq_mono[rule_format, OF conjI[OF H nb]] + by (simp add: DVD_def rdvd_left_0_eq)} + moreover {assume inz: "i\0" and "n=0" hence ?th by (simp add: H DVD_def) } + moreover {assume inz: "i\0" and "n<0" hence ?th + by (simp add: DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1 + rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } + moreover {assume inz: "i\0" and "n>0" hence ?th by (simp add:DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1)} + ultimately show ?th by blast +qed + +lemma NDVD_mono: assumes xp: "0\ x" and x1: "x < 1" + shows "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (NDVD i n s) = Ifm (x#bs) (NDvd i a)" + (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (NDVD i n s) = ?I (NDvd i a)") +proof(clarify) + fix a n s + assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s" + let ?th = "?I (NDVD i n s) = ?I (NDvd i a)" + have "i=0 \ (i\0 \ n=0) \ (i\0 \ n < 0) \ (i\0 \ n > 0)" by arith + moreover {assume iz: "i=0" hence ?th using neq_mono[rule_format, OF conjI[OF H nb]] + by (simp add: NDVD_def rdvd_left_0_eq)} + moreover {assume inz: "i\0" and "n=0" hence ?th by (simp add: H NDVD_def) } + moreover {assume inz: "i\0" and "n<0" hence ?th + by (simp add: NDVD_def H NDVDJ_NDVD[OF xp x1] rdvd_abs1 + rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } + moreover {assume inz: "i\0" and "n>0" hence ?th + by (simp add:NDVD_def H NDVDJ_NDVD[OF xp x1] rdvd_abs1)} + ultimately show ?th by blast +qed + +lemma DVD_l: "isrlfm (rsplit (DVD i) a)" + by (rule rsplit_l[where f="DVD i" and a="a"], auto simp add: DVD_def eq_def DVDJ_l) +(case_tac s, simp_all, case_tac "nat", simp_all) + +lemma NDVD_l: "isrlfm (rsplit (NDVD i) a)" + by (rule rsplit_l[where f="NDVD i" and a="a"], auto simp add: NDVD_def neq_def NDVDJ_l) +(case_tac s, simp_all, case_tac "nat", simp_all) + +consts rlfm :: "fm \ fm" +recdef rlfm "measure fmsize" + "rlfm (And p q) = conj (rlfm p) (rlfm q)" + "rlfm (Or p q) = disj (rlfm p) (rlfm q)" + "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)" + "rlfm (Iff p q) = disj (conj(rlfm p) (rlfm q)) (conj(rlfm (NOT p)) (rlfm (NOT q)))" + "rlfm (Lt a) = rsplit lt a" + "rlfm (Le a) = rsplit le a" + "rlfm (Gt a) = rsplit gt a" + "rlfm (Ge a) = rsplit ge a" + "rlfm (Eq a) = rsplit eq a" + "rlfm (NEq a) = rsplit neq a" + "rlfm (Dvd i a) = rsplit (\ t. DVD i t) a" + "rlfm (NDvd i a) = rsplit (\ t. NDVD i t) a" + "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))" + "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))" + "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))" + "rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))" + "rlfm (NOT (NOT p)) = rlfm p" + "rlfm (NOT T) = F" + "rlfm (NOT F) = T" + "rlfm (NOT (Lt a)) = simpfm (rlfm (Ge a))" + "rlfm (NOT (Le a)) = simpfm (rlfm (Gt a))" + "rlfm (NOT (Gt a)) = simpfm (rlfm (Le a))" + "rlfm (NOT (Ge a)) = simpfm (rlfm (Lt a))" + "rlfm (NOT (Eq a)) = simpfm (rlfm (NEq a))" + "rlfm (NOT (NEq a)) = simpfm (rlfm (Eq a))" + "rlfm (NOT (Dvd i a)) = simpfm (rlfm (NDvd i a))" + "rlfm (NOT (NDvd i a)) = simpfm (rlfm (Dvd i a))" + "rlfm p = p" (hints simp add: fmsize_pos) + +lemma bound0at_l : "\isatom p ; bound0 p\ \ isrlfm p" + by (induct p rule: isrlfm.induct, auto) +lemma zgcd_le1: assumes ip: "0 < i" shows "zgcd i j \ i" +proof- + from zgcd_zdvd1 have th: "zgcd i j dvd i" by blast + from zdvd_imp_le[OF th ip] show ?thesis . +qed + + +lemma simpfm_rl: "isrlfm p \ isrlfm (simpfm p)" +proof (induct p) + case (Lt a) + hence "bound0 (Lt a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" + by (cases a,simp_all, case_tac "nat", simp_all) + moreover + {assume "bound0 (Lt a)" hence bn:"bound0 (simpfm (Lt a))" + using simpfm_bound0 by blast + have "isatom (simpfm (Lt a))" by (cases "simpnum a", auto simp add: Let_def) + with bn bound0at_l have ?case by blast} + moreover + {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" + { + assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" + with numgcd_pos[where t="CN 0 c (simpnum e)"] + have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp + from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" + by (simp add: numgcd_def zgcd_le1) + from prems have th': "c\0" by auto + from prems have cp: "c \ 0" by simp + from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] + have "0 < c div numgcd (CN 0 c (simpnum e))" by simp + } + with prems have ?case + by (simp add: Let_def reducecoeff_def reducecoeffh_numbound0)} + ultimately show ?case by blast +next + case (Le a) + hence "bound0 (Le a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" + by (cases a,simp_all, case_tac "nat", simp_all) + moreover + {assume "bound0 (Le a)" hence bn:"bound0 (simpfm (Le a))" + using simpfm_bound0 by blast + have "isatom (simpfm (Le a))" by (cases "simpnum a", auto simp add: Let_def) + with bn bound0at_l have ?case by blast} + moreover + {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" + { + assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" + with numgcd_pos[where t="CN 0 c (simpnum e)"] + have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp + from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" + by (simp add: numgcd_def zgcd_le1) + from prems have th': "c\0" by auto + from prems have cp: "c \ 0" by simp + from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] + have "0 < c div numgcd (CN 0 c (simpnum e))" by simp + } + with prems have ?case + by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} + ultimately show ?case by blast +next + case (Gt a) + hence "bound0 (Gt a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" + by (cases a,simp_all, case_tac "nat", simp_all) + moreover + {assume "bound0 (Gt a)" hence bn:"bound0 (simpfm (Gt a))" + using simpfm_bound0 by blast + have "isatom (simpfm (Gt a))" by (cases "simpnum a", auto simp add: Let_def) + with bn bound0at_l have ?case by blast} + moreover + {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" + { + assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" + with numgcd_pos[where t="CN 0 c (simpnum e)"] + have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp + from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" + by (simp add: numgcd_def zgcd_le1) + from prems have th': "c\0" by auto + from prems have cp: "c \ 0" by simp + from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] + have "0 < c div numgcd (CN 0 c (simpnum e))" by simp + } + with prems have ?case + by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} + ultimately show ?case by blast +next + case (Ge a) + hence "bound0 (Ge a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" + by (cases a,simp_all, case_tac "nat", simp_all) + moreover + {assume "bound0 (Ge a)" hence bn:"bound0 (simpfm (Ge a))" + using simpfm_bound0 by blast + have "isatom (simpfm (Ge a))" by (cases "simpnum a", auto simp add: Let_def) + with bn bound0at_l have ?case by blast} + moreover + {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" + { + assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" + with numgcd_pos[where t="CN 0 c (simpnum e)"] + have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp + from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" + by (simp add: numgcd_def zgcd_le1) + from prems have th': "c\0" by auto + from prems have cp: "c \ 0" by simp + from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] + have "0 < c div numgcd (CN 0 c (simpnum e))" by simp + } + with prems have ?case + by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} + ultimately show ?case by blast +next + case (Eq a) + hence "bound0 (Eq a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" + by (cases a,simp_all, case_tac "nat", simp_all) + moreover + {assume "bound0 (Eq a)" hence bn:"bound0 (simpfm (Eq a))" + using simpfm_bound0 by blast + have "isatom (simpfm (Eq a))" by (cases "simpnum a", auto simp add: Let_def) + with bn bound0at_l have ?case by blast} + moreover + {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" + { + assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" + with numgcd_pos[where t="CN 0 c (simpnum e)"] + have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp + from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" + by (simp add: numgcd_def zgcd_le1) + from prems have th': "c\0" by auto + from prems have cp: "c \ 0" by simp + from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] + have "0 < c div numgcd (CN 0 c (simpnum e))" by simp + } + with prems have ?case + by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} + ultimately show ?case by blast +next + case (NEq a) + hence "bound0 (NEq a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" + by (cases a,simp_all, case_tac "nat", simp_all) + moreover + {assume "bound0 (NEq a)" hence bn:"bound0 (simpfm (NEq a))" + using simpfm_bound0 by blast + have "isatom (simpfm (NEq a))" by (cases "simpnum a", auto simp add: Let_def) + with bn bound0at_l have ?case by blast} + moreover + {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" + { + assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" + with numgcd_pos[where t="CN 0 c (simpnum e)"] + have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp + from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" + by (simp add: numgcd_def zgcd_le1) + from prems have th': "c\0" by auto + from prems have cp: "c \ 0" by simp + from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] + have "0 < c div numgcd (CN 0 c (simpnum e))" by simp + } + with prems have ?case + by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} + ultimately show ?case by blast +next + case (Dvd i a) hence "bound0 (Dvd i a)" by auto hence bn:"bound0 (simpfm (Dvd i a))" + using simpfm_bound0 by blast + have "isatom (simpfm (Dvd i a))" by (cases "simpnum a", auto simp add: Let_def split_def) + with bn bound0at_l show ?case by blast +next + case (NDvd i a) hence "bound0 (NDvd i a)" by auto hence bn:"bound0 (simpfm (NDvd i a))" + using simpfm_bound0 by blast + have "isatom (simpfm (NDvd i a))" by (cases "simpnum a", auto simp add: Let_def split_def) + with bn bound0at_l show ?case by blast +qed(auto simp add: conj_def imp_def disj_def iff_def Let_def simpfm_bound0 numadd_nb numneg_nb) + +lemma rlfm_I: + assumes qfp: "qfree p" + and xp: "0 \ x" and x1: "x < 1" + shows "(Ifm (x#bs) (rlfm p) = Ifm (x# bs) p) \ isrlfm (rlfm p)" + using qfp +by (induct p rule: rlfm.induct) +(auto simp add: rsplit[OF xp x1 lt_mono] lt_l rsplit[OF xp x1 le_mono] le_l rsplit[OF xp x1 gt_mono] gt_l + rsplit[OF xp x1 ge_mono] ge_l rsplit[OF xp x1 eq_mono] eq_l rsplit[OF xp x1 neq_mono] neq_l + rsplit[OF xp x1 DVD_mono[OF xp x1]] DVD_l rsplit[OF xp x1 NDVD_mono[OF xp x1]] NDVD_l simpfm_rl) +lemma rlfm_l: + assumes qfp: "qfree p" + shows "isrlfm (rlfm p)" + using qfp lt_l gt_l ge_l le_l eq_l neq_l DVD_l NDVD_l +by (induct p rule: rlfm.induct,auto simp add: simpfm_rl) + + (* Operations needed for Ferrante and Rackoff *) +lemma rminusinf_inf: + assumes lp: "isrlfm p" + shows "\ z. \ x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\ z. \ x. ?P z x p") +using lp +proof (induct p rule: minusinf.induct) + case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto +next + case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto +next + case (3 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x < ?z" + hence "(real c * x < - ?e)" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) + hence "real c * x + ?e < 0" by arith + hence "real c * x + ?e \ 0" by simp + with xz have "?P ?z x (Eq (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp + thus ?case by blast +next + case (4 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x < ?z" + hence "(real c * x < - ?e)" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) + hence "real c * x + ?e < 0" by arith + hence "real c * x + ?e \ 0" by simp + with xz have "?P ?z x (NEq (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp + thus ?case by blast +next + case (5 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x < ?z" + hence "(real c * x < - ?e)" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) + hence "real c * x + ?e < 0" by arith + with xz have "?P ?z x (Lt (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp + thus ?case by blast +next + case (6 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x < ?z" + hence "(real c * x < - ?e)" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) + hence "real c * x + ?e < 0" by arith + with xz have "?P ?z x (Le (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x < ?z. ?P ?z x (Le (CN 0 c e))" by simp + thus ?case by blast +next + case (7 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x < ?z" + hence "(real c * x < - ?e)" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) + hence "real c * x + ?e < 0" by arith + with xz have "?P ?z x (Gt (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp + thus ?case by blast +next + case (8 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x < ?z" + hence "(real c * x < - ?e)" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) + hence "real c * x + ?e < 0" by arith + with xz have "?P ?z x (Ge (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp + thus ?case by blast +qed simp_all + +lemma rplusinf_inf: + assumes lp: "isrlfm p" + shows "\ z. \ x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\ z. \ x. ?P z x p") +using lp +proof (induct p rule: isrlfm.induct) + case (1 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto +next + case (2 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto +next + case (3 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x > ?z" + with mult_strict_right_mono [OF xz cp] cp + have "(real c * x > - ?e)" by (simp add: mult_ac) + hence "real c * x + ?e > 0" by arith + hence "real c * x + ?e \ 0" by simp + with xz have "?P ?z x (Eq (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp + thus ?case by blast +next + case (4 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x > ?z" + with mult_strict_right_mono [OF xz cp] cp + have "(real c * x > - ?e)" by (simp add: mult_ac) + hence "real c * x + ?e > 0" by arith + hence "real c * x + ?e \ 0" by simp + with xz have "?P ?z x (NEq (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp + thus ?case by blast +next + case (5 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x > ?z" + with mult_strict_right_mono [OF xz cp] cp + have "(real c * x > - ?e)" by (simp add: mult_ac) + hence "real c * x + ?e > 0" by arith + with xz have "?P ?z x (Lt (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp + thus ?case by blast +next + case (6 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x > ?z" + with mult_strict_right_mono [OF xz cp] cp + have "(real c * x > - ?e)" by (simp add: mult_ac) + hence "real c * x + ?e > 0" by arith + with xz have "?P ?z x (Le (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x > ?z. ?P ?z x (Le (CN 0 c e))" by simp + thus ?case by blast +next + case (7 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x > ?z" + with mult_strict_right_mono [OF xz cp] cp + have "(real c * x > - ?e)" by (simp add: mult_ac) + hence "real c * x + ?e > 0" by arith + with xz have "?P ?z x (Gt (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp + thus ?case by blast +next + case (8 c e) + from prems have nb: "numbound0 e" by simp + from prems have cp: "real c > 0" by simp + fix a + let ?e="Inum (a#bs) e" + let ?z = "(- ?e) / real c" + {fix x + assume xz: "x > ?z" + with mult_strict_right_mono [OF xz cp] cp + have "(real c * x > - ?e)" by (simp add: mult_ac) + hence "real c * x + ?e > 0" by arith + with xz have "?P ?z x (Ge (CN 0 c e))" + using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } + hence "\ x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp + thus ?case by blast +qed simp_all + +lemma rminusinf_bound0: + assumes lp: "isrlfm p" + shows "bound0 (minusinf p)" + using lp + by (induct p rule: minusinf.induct) simp_all + +lemma rplusinf_bound0: + assumes lp: "isrlfm p" + shows "bound0 (plusinf p)" + using lp + by (induct p rule: plusinf.induct) simp_all + +lemma rminusinf_ex: + assumes lp: "isrlfm p" + and ex: "Ifm (a#bs) (minusinf p)" + shows "\ x. Ifm (x#bs) p" +proof- + from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex + have th: "\ x. Ifm (x#bs) (minusinf p)" by auto + from rminusinf_inf[OF lp, where bs="bs"] + obtain z where z_def: "\x x. Ifm (x#bs) p" +proof- + from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex + have th: "\ x. Ifm (x#bs) (plusinf p)" by auto + from rplusinf_inf[OF lp, where bs="bs"] + obtain z where z_def: "\x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast + from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp + moreover have "z + 1 > z" by simp + ultimately show ?thesis using z_def by auto +qed + +consts + \:: "fm \ (num \ int) list" + \ :: "fm \ (num \ int) \ fm " +recdef \ "measure size" + "\ (And p q) = (\ p @ \ q)" + "\ (Or p q) = (\ p @ \ q)" + "\ (Eq (CN 0 c e)) = [(Neg e,c)]" + "\ (NEq (CN 0 c e)) = [(Neg e,c)]" + "\ (Lt (CN 0 c e)) = [(Neg e,c)]" + "\ (Le (CN 0 c e)) = [(Neg e,c)]" + "\ (Gt (CN 0 c e)) = [(Neg e,c)]" + "\ (Ge (CN 0 c e)) = [(Neg e,c)]" + "\ p = []" + +recdef \ "measure size" + "\ (And p q) = (\ (t,n). And (\ p (t,n)) (\ q (t,n)))" + "\ (Or p q) = (\ (t,n). Or (\ p (t,n)) (\ q (t,n)))" + "\ (Eq (CN 0 c e)) = (\ (t,n). Eq (Add (Mul c t) (Mul n e)))" + "\ (NEq (CN 0 c e)) = (\ (t,n). NEq (Add (Mul c t) (Mul n e)))" + "\ (Lt (CN 0 c e)) = (\ (t,n). Lt (Add (Mul c t) (Mul n e)))" + "\ (Le (CN 0 c e)) = (\ (t,n). Le (Add (Mul c t) (Mul n e)))" + "\ (Gt (CN 0 c e)) = (\ (t,n). Gt (Add (Mul c t) (Mul n e)))" + "\ (Ge (CN 0 c e)) = (\ (t,n). Ge (Add (Mul c t) (Mul n e)))" + "\ p = (\ (t,n). p)" + +lemma \_I: assumes lp: "isrlfm p" + and np: "real n > 0" and nbt: "numbound0 t" + shows "(Ifm (x#bs) (\ p (t,n)) = Ifm (((Inum (x#bs) t)/(real n))#bs) p) \ bound0 (\ p (t,n))" (is "(?I x (\ p (t,n)) = ?I ?u p) \ ?B p" is "(_ = ?I (?t/?n) p) \ _" is "(_ = ?I (?N x t /_) p) \ _") + using lp +proof(induct p rule: \.induct) + case (5 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ + have "?I ?u (Lt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) < 0)" + using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp + also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)" + by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" + and b="0", simplified divide_zero_left]) (simp only: algebra_simps) + also have "\ = (real c *?t + ?n* (?N x e) < 0)" + using np by simp + finally show ?case using nbt nb by (simp add: algebra_simps) +next + case (6 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ + have "?I ?u (Le (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" + using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp + also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" + by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" + and b="0", simplified divide_zero_left]) (simp only: algebra_simps) + also have "\ = (real c *?t + ?n* (?N x e) \ 0)" + using np by simp + finally show ?case using nbt nb by (simp add: algebra_simps) +next + case (7 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ + have "?I ?u (Gt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) > 0)" + using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp + also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)" + by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)" + and b="0", simplified divide_zero_left]) (simp only: algebra_simps) + also have "\ = (real c *?t + ?n* (?N x e) > 0)" + using np by simp + finally show ?case using nbt nb by (simp add: algebra_simps) +next + case (8 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ + have "?I ?u (Ge (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" + using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp + also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" + by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)" + and b="0", simplified divide_zero_left]) (simp only: algebra_simps) + also have "\ = (real c *?t + ?n* (?N x e) \ 0)" + using np by simp + finally show ?case using nbt nb by (simp add: algebra_simps) +next + case (3 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ + from np have np: "real n \ 0" by simp + have "?I ?u (Eq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) = 0)" + using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp + also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) = 0)" + by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" + and b="0", simplified divide_zero_left]) (simp only: algebra_simps) + also have "\ = (real c *?t + ?n* (?N x e) = 0)" + using np by simp + finally show ?case using nbt nb by (simp add: algebra_simps) +next + case (4 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ + from np have np: "real n \ 0" by simp + have "?I ?u (NEq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" + using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp + also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" + by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" + and b="0", simplified divide_zero_left]) (simp only: algebra_simps) + also have "\ = (real c *?t + ?n* (?N x e) \ 0)" + using np by simp + finally show ?case using nbt nb by (simp add: algebra_simps) +qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"] nth_pos2) + +lemma \_l: + assumes lp: "isrlfm p" + shows "\ (t,k) \ set (\ p). numbound0 t \ k >0" +using lp +by(induct p rule: \.induct) auto + +lemma rminusinf_\: + assumes lp: "isrlfm p" + and nmi: "\ (Ifm (a#bs) (minusinf p))" (is "\ (Ifm (a#bs) (?M p))") + and ex: "Ifm (x#bs) p" (is "?I x p") + shows "\ (s,m) \ set (\ p). x \ Inum (a#bs) s / real m" (is "\ (s,m) \ ?U p. x \ ?N a s / real m") +proof- + have "\ (s,m) \ set (\ p). real m * x \ Inum (a#bs) s " (is "\ (s,m) \ ?U p. real m *x \ ?N a s") + using lp nmi ex + by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2) + then obtain s m where smU: "(s,m) \ set (\ p)" and mx: "real m * x \ ?N a s" by blast + from \_l[OF lp] smU have mp: "real m > 0" by auto + from pos_divide_le_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \ ?N a s / real m" + by (auto simp add: mult_commute) + thus ?thesis using smU by auto +qed + +lemma rplusinf_\: + assumes lp: "isrlfm p" + and nmi: "\ (Ifm (a#bs) (plusinf p))" (is "\ (Ifm (a#bs) (?M p))") + and ex: "Ifm (x#bs) p" (is "?I x p") + shows "\ (s,m) \ set (\ p). x \ Inum (a#bs) s / real m" (is "\ (s,m) \ ?U p. x \ ?N a s / real m") +proof- + have "\ (s,m) \ set (\ p). real m * x \ Inum (a#bs) s " (is "\ (s,m) \ ?U p. real m *x \ ?N a s") + using lp nmi ex + by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2) + then obtain s m where smU: "(s,m) \ set (\ p)" and mx: "real m * x \ ?N a s" by blast + from \_l[OF lp] smU have mp: "real m > 0" by auto + from pos_le_divide_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \ ?N a s / real m" + by (auto simp add: mult_commute) + thus ?thesis using smU by auto +qed + +lemma lin_dense: + assumes lp: "isrlfm p" + and noS: "\ t. l < t \ t< u \ t \ (\ (t,n). Inum (x#bs) t / real n) ` set (\ p)" + (is "\ t. _ \ _ \ t \ (\ (t,n). ?N x t / real n ) ` (?U p)") + and lx: "l < x" and xu:"x < u" and px:" Ifm (x#bs) p" + and ly: "l < y" and yu: "y < u" + shows "Ifm (y#bs) p" +using lp px noS +proof (induct p rule: isrlfm.induct) + case (5 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ + from prems have "x * real c + ?N x e < 0" by (simp add: algebra_simps) + hence pxc: "x < (- ?N x e) / real c" + by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"]) + from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto + with ly yu have yne: "y \ - ?N x e / real c" by auto + hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto + moreover {assume y: "y < (-?N x e)/ real c" + hence "y * real c < - ?N x e" + by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) + hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) + hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} + moreover {assume y: "y > (- ?N x e) / real c" + with yu have eu: "u > (- ?N x e) / real c" by auto + with noSc ly yu have "(- ?N x e) / real c \ l" by (cases "(- ?N x e) / real c > l", auto) + with lx pxc have "False" by auto + hence ?case by simp } + ultimately show ?case by blast +next + case (6 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp + + from prems have "x * real c + ?N x e \ 0" by (simp add: algebra_simps) + hence pxc: "x \ (- ?N x e) / real c" + by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"]) + from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto + with ly yu have yne: "y \ - ?N x e / real c" by auto + hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto + moreover {assume y: "y < (-?N x e)/ real c" + hence "y * real c < - ?N x e" + by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) + hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) + hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} + moreover {assume y: "y > (- ?N x e) / real c" + with yu have eu: "u > (- ?N x e) / real c" by auto + with noSc ly yu have "(- ?N x e) / real c \ l" by (cases "(- ?N x e) / real c > l", auto) + with lx pxc have "False" by auto + hence ?case by simp } + ultimately show ?case by blast +next + case (7 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ + from prems have "x * real c + ?N x e > 0" by (simp add: algebra_simps) + hence pxc: "x > (- ?N x e) / real c" + by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"]) + from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto + with ly yu have yne: "y \ - ?N x e / real c" by auto + hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto + moreover {assume y: "y > (-?N x e)/ real c" + hence "y * real c > - ?N x e" + by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) + hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) + hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} + moreover {assume y: "y < (- ?N x e) / real c" + with ly have eu: "l < (- ?N x e) / real c" by auto + with noSc ly yu have "(- ?N x e) / real c \ u" by (cases "(- ?N x e) / real c > l", auto) + with xu pxc have "False" by auto + hence ?case by simp } + ultimately show ?case by blast +next + case (8 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ + from prems have "x * real c + ?N x e \ 0" by (simp add: algebra_simps) + hence pxc: "x \ (- ?N x e) / real c" + by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"]) + from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto + with ly yu have yne: "y \ - ?N x e / real c" by auto + hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto + moreover {assume y: "y > (-?N x e)/ real c" + hence "y * real c > - ?N x e" + by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) + hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) + hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} + moreover {assume y: "y < (- ?N x e) / real c" + with ly have eu: "l < (- ?N x e) / real c" by auto + with noSc ly yu have "(- ?N x e) / real c \ u" by (cases "(- ?N x e) / real c > l", auto) + with xu pxc have "False" by auto + hence ?case by simp } + ultimately show ?case by blast +next + case (3 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ + from cp have cnz: "real c \ 0" by simp + from prems have "x * real c + ?N x e = 0" by (simp add: algebra_simps) + hence pxc: "x = (- ?N x e) / real c" + by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"]) + from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto + with lx xu have yne: "x \ - ?N x e / real c" by auto + with pxc show ?case by simp +next + case (4 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ + from cp have cnz: "real c \ 0" by simp + from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto + with ly yu have yne: "y \ - ?N x e / real c" by auto + hence "y* real c \ -?N x e" + by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp + hence "y* real c + ?N x e \ 0" by (simp add: algebra_simps) + thus ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] + by (simp add: algebra_simps) +qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="y" and b'="x"]) + +lemma finite_set_intervals: + assumes px: "P (x::real)" + and lx: "l \ x" and xu: "x \ u" + and linS: "l\ S" and uinS: "u \ S" + and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" + shows "\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a \ x \ x \ b \ P x" +proof- + let ?Mx = "{y. y\ S \ y \ x}" + let ?xM = "{y. y\ S \ x \ y}" + let ?a = "Max ?Mx" + let ?b = "Min ?xM" + have MxS: "?Mx \ S" by blast + hence fMx: "finite ?Mx" using fS finite_subset by auto + from lx linS have linMx: "l \ ?Mx" by blast + hence Mxne: "?Mx \ {}" by blast + have xMS: "?xM \ S" by blast + hence fxM: "finite ?xM" using fS finite_subset by auto + from xu uinS have linxM: "u \ ?xM" by blast + hence xMne: "?xM \ {}" by blast + have ax:"?a \ x" using Mxne fMx by auto + have xb:"x \ ?b" using xMne fxM by auto + have "?a \ ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \ S" using MxS by blast + have "?b \ ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \ S" using xMS by blast + have noy:"\ y. ?a < y \ y < ?b \ y \ S" + proof(clarsimp) + fix y + assume ay: "?a < y" and yb: "y < ?b" and yS: "y \ S" + from yS have "y\ ?Mx \ y\ ?xM" by auto + moreover {assume "y \ ?Mx" hence "y \ ?a" using Mxne fMx by auto with ay have "False" by simp} + moreover {assume "y \ ?xM" hence "y \ ?b" using xMne fxM by auto with yb have "False" by simp} + ultimately show "False" by blast + qed + from ainS binS noy ax xb px show ?thesis by blast +qed + +lemma finite_set_intervals2: + assumes px: "P (x::real)" + and lx: "l \ x" and xu: "x \ u" + and linS: "l\ S" and uinS: "u \ S" + and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" + shows "(\ s\ S. P s) \ (\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a < x \ x < b \ P x)" +proof- + from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su] + obtain a and b where + as: "a\ S" and bs: "b\ S" and noS:"\y. a < y \ y < b \ y \ S" and axb: "a \ x \ x \ b \ P x" by auto + from axb have "x= a \ x= b \ (a < x \ x < b)" by auto + thus ?thesis using px as bs noS by blast +qed + +lemma rinf_\: + assumes lp: "isrlfm p" + and nmi: "\ (Ifm (x#bs) (minusinf p))" (is "\ (Ifm (x#bs) (?M p))") + and npi: "\ (Ifm (x#bs) (plusinf p))" (is "\ (Ifm (x#bs) (?P p))") + and ex: "\ x. Ifm (x#bs) p" (is "\ x. ?I x p") + shows "\ (l,n) \ set (\ p). \ (s,m) \ set (\ p). ?I ((Inum (x#bs) l / real n + Inum (x#bs) s / real m) / 2) p" +proof- + let ?N = "\ x t. Inum (x#bs) t" + let ?U = "set (\ p)" + from ex obtain a where pa: "?I a p" by blast + from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi + have nmi': "\ (?I a (?M p))" by simp + from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi + have npi': "\ (?I a (?P p))" by simp + have "\ (l,n) \ set (\ p). \ (s,m) \ set (\ p). ?I ((?N a l/real n + ?N a s /real m) / 2) p" + proof- + let ?M = "(\ (t,c). ?N a t / real c) ` ?U" + have fM: "finite ?M" by auto + from rminusinf_\[OF lp nmi pa] rplusinf_\[OF lp npi pa] + have "\ (l,n) \ set (\ p). \ (s,m) \ set (\ p). a \ ?N x l / real n \ a \ ?N x s / real m" by blast + then obtain "t" "n" "s" "m" where + tnU: "(t,n) \ ?U" and smU: "(s,m) \ ?U" + and xs1: "a \ ?N x s / real m" and tx1: "a \ ?N x t / real n" by blast + from \_l[OF lp] tnU smU numbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 have xs: "a \ ?N a s / real m" and tx: "a \ ?N a t / real n" by auto + from tnU have Mne: "?M \ {}" by auto + hence Une: "?U \ {}" by simp + let ?l = "Min ?M" + let ?u = "Max ?M" + have linM: "?l \ ?M" using fM Mne by simp + have uinM: "?u \ ?M" using fM Mne by simp + have tnM: "?N a t / real n \ ?M" using tnU by auto + have smM: "?N a s / real m \ ?M" using smU by auto + have lM: "\ t\ ?M. ?l \ t" using Mne fM by auto + have Mu: "\ t\ ?M. t \ ?u" using Mne fM by auto + have "?l \ ?N a t / real n" using tnM Mne by simp hence lx: "?l \ a" using tx by simp + have "?N a s / real m \ ?u" using smM Mne by simp hence xu: "a \ ?u" using xs by simp + from finite_set_intervals2[where P="\ x. ?I x p",OF pa lx xu linM uinM fM lM Mu] + have "(\ s\ ?M. ?I s p) \ + (\ t1\ ?M. \ t2 \ ?M. (\ y. t1 < y \ y < t2 \ y \ ?M) \ t1 < a \ a < t2 \ ?I a p)" . + moreover { fix u assume um: "u\ ?M" and pu: "?I u p" + hence "\ (tu,nu) \ ?U. u = ?N a tu / real nu" by auto + then obtain "tu" "nu" where tuU: "(tu,nu) \ ?U" and tuu:"u= ?N a tu / real nu" by blast + have "(u + u) / 2 = u" by auto with pu tuu + have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" by simp + with tuU have ?thesis by blast} + moreover{ + assume "\ t1\ ?M. \ t2 \ ?M. (\ y. t1 < y \ y < t2 \ y \ ?M) \ t1 < a \ a < t2 \ ?I a p" + then obtain t1 and t2 where t1M: "t1 \ ?M" and t2M: "t2\ ?M" + and noM: "\ y. t1 < y \ y < t2 \ y \ ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p" + by blast + from t1M have "\ (t1u,t1n) \ ?U. t1 = ?N a t1u / real t1n" by auto + then obtain "t1u" "t1n" where t1uU: "(t1u,t1n) \ ?U" and t1u: "t1 = ?N a t1u / real t1n" by blast + from t2M have "\ (t2u,t2n) \ ?U. t2 = ?N a t2u / real t2n" by auto + then obtain "t2u" "t2n" where t2uU: "(t2u,t2n) \ ?U" and t2u: "t2 = ?N a t2u / real t2n" by blast + from t1x xt2 have t1t2: "t1 < t2" by simp + let ?u = "(t1 + t2) / 2" + from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto + from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" . + with t1uU t2uU t1u t2u have ?thesis by blast} + ultimately show ?thesis by blast + qed + then obtain "l" "n" "s" "m" where lnU: "(l,n) \ ?U" and smU:"(s,m) \ ?U" + and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" by blast + from lnU smU \_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" by auto + from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] + numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu + have "?I ((?N x l / real n + ?N x s / real m) / 2) p" by simp + with lnU smU + show ?thesis by auto +qed + (* The Ferrante - Rackoff Theorem *) + +theorem fr_eq: + assumes lp: "isrlfm p" + shows "(\ x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \ (Ifm (x#bs) (plusinf p)) \ (\ (t,n) \ set (\ p). \ (s,m) \ set (\ p). Ifm ((((Inum (x#bs) t)/ real n + (Inum (x#bs) s) / real m) /2)#bs) p))" + (is "(\ x. ?I x p) = (?M \ ?P \ ?F)" is "?E = ?D") +proof + assume px: "\ x. ?I x p" + have "?M \ ?P \ (\ ?M \ \ ?P)" by blast + moreover {assume "?M \ ?P" hence "?D" by blast} + moreover {assume nmi: "\ ?M" and npi: "\ ?P" + from rinf_\[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast} + ultimately show "?D" by blast +next + assume "?D" + moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} + moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } + moreover {assume f:"?F" hence "?E" by blast} + ultimately show "?E" by blast +qed + + +lemma fr_eq\: + assumes lp: "isrlfm p" + shows "(\ x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \ (Ifm (x#bs) (plusinf p)) \ (\ (t,k) \ set (\ p). \ (s,l) \ set (\ p). Ifm (x#bs) (\ p (Add(Mul l t) (Mul k s) , 2*k*l))))" + (is "(\ x. ?I x p) = (?M \ ?P \ ?F)" is "?E = ?D") +proof + assume px: "\ x. ?I x p" + have "?M \ ?P \ (\ ?M \ \ ?P)" by blast + moreover {assume "?M \ ?P" hence "?D" by blast} + moreover {assume nmi: "\ ?M" and npi: "\ ?P" + let ?f ="\ (t,n). Inum (x#bs) t / real n" + let ?N = "\ t. Inum (x#bs) t" + {fix t n s m assume "(t,n)\ set (\ p)" and "(s,m) \ set (\ p)" + with \_l[OF lp] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0" + by auto + let ?st = "Add (Mul m t) (Mul n s)" + from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" + by (simp add: mult_commute) + from tnb snb have st_nb: "numbound0 ?st" by simp + have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" + using mnp mp np by (simp add: algebra_simps add_divide_distrib) + from \_I[OF lp mnp st_nb, where x="x" and bs="bs"] + have "?I x (\ p (?st,2*n*m)) = ?I ((?N t / real n + ?N s / real m) /2) p" by (simp only: st[symmetric])} + with rinf_\[OF lp nmi npi px] have "?F" by blast hence "?D" by blast} + ultimately show "?D" by blast +next + assume "?D" + moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} + moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } + moreover {fix t k s l assume "(t,k) \ set (\ p)" and "(s,l) \ set (\ p)" + and px:"?I x (\ p (Add (Mul l t) (Mul k s), 2*k*l))" + with \_l[OF lp] have tnb: "numbound0 t" and np:"real k > 0" and snb: "numbound0 s" and mp:"real l > 0" by auto + let ?st = "Add (Mul l t) (Mul k s)" + from mult_pos_pos[OF np mp] have mnp: "real (2*k*l) > 0" + by (simp add: mult_commute) + from tnb snb have st_nb: "numbound0 ?st" by simp + from \_I[OF lp mnp st_nb, where bs="bs"] px have "?E" by auto} + ultimately show "?E" by blast +qed + +text{* The overall Part *} + +lemma real_ex_int_real01: + shows "(\ (x::real). P x) = (\ (i::int) (u::real). 0\ u \ u< 1 \ P (real i + u))" +proof(auto) + fix x + assume Px: "P x" + let ?i = "floor x" + let ?u = "x - real ?i" + have "x = real ?i + ?u" by simp + hence "P (real ?i + ?u)" using Px by simp + moreover have "real ?i \ x" using real_of_int_floor_le by simp hence "0 \ ?u" by arith + moreover have "?u < 1" using real_of_int_floor_add_one_gt[where r="x"] by arith + ultimately show "(\ (i::int) (u::real). 0\ u \ u< 1 \ P (real i + u))" by blast +qed + +consts exsplitnum :: "num \ num" + exsplit :: "fm \ fm" +recdef exsplitnum "measure size" + "exsplitnum (C c) = (C c)" + "exsplitnum (Bound 0) = Add (Bound 0) (Bound 1)" + "exsplitnum (Bound n) = Bound (n+1)" + "exsplitnum (Neg a) = Neg (exsplitnum a)" + "exsplitnum (Add a b) = Add (exsplitnum a) (exsplitnum b) " + "exsplitnum (Sub a b) = Sub (exsplitnum a) (exsplitnum b) " + "exsplitnum (Mul c a) = Mul c (exsplitnum a)" + "exsplitnum (Floor a) = Floor (exsplitnum a)" + "exsplitnum (CN 0 c a) = CN 0 c (Add (Mul c (Bound 1)) (exsplitnum a))" + "exsplitnum (CN n c a) = CN (n+1) c (exsplitnum a)" + "exsplitnum (CF c s t) = CF c (exsplitnum s) (exsplitnum t)" + +recdef exsplit "measure size" + "exsplit (Lt a) = Lt (exsplitnum a)" + "exsplit (Le a) = Le (exsplitnum a)" + "exsplit (Gt a) = Gt (exsplitnum a)" + "exsplit (Ge a) = Ge (exsplitnum a)" + "exsplit (Eq a) = Eq (exsplitnum a)" + "exsplit (NEq a) = NEq (exsplitnum a)" + "exsplit (Dvd i a) = Dvd i (exsplitnum a)" + "exsplit (NDvd i a) = NDvd i (exsplitnum a)" + "exsplit (And p q) = And (exsplit p) (exsplit q)" + "exsplit (Or p q) = Or (exsplit p) (exsplit q)" + "exsplit (Imp p q) = Imp (exsplit p) (exsplit q)" + "exsplit (Iff p q) = Iff (exsplit p) (exsplit q)" + "exsplit (NOT p) = NOT (exsplit p)" + "exsplit p = p" + +lemma exsplitnum: + "Inum (x#y#bs) (exsplitnum t) = Inum ((x+y) #bs) t" + by(induct t rule: exsplitnum.induct) (simp_all add: algebra_simps) + +lemma exsplit: + assumes qfp: "qfree p" + shows "Ifm (x#y#bs) (exsplit p) = Ifm ((x+y)#bs) p" +using qfp exsplitnum[where x="x" and y="y" and bs="bs"] +by(induct p rule: exsplit.induct) simp_all + +lemma splitex: + assumes qf: "qfree p" + shows "(Ifm bs (E p)) = (\ (i::int). Ifm (real i#bs) (E (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) (exsplit p))))" (is "?lhs = ?rhs") +proof- + have "?rhs = (\ (i::int). \ x. 0\ x \ x < 1 \ Ifm (x#(real i)#bs) (exsplit p))" + by (simp add: myless[rule_format, where b="1"] myless[rule_format, where b="0"] add_ac diff_def) + also have "\ = (\ (i::int). \ x. 0\ x \ x < 1 \ Ifm ((real i + x) #bs) p)" + by (simp only: exsplit[OF qf] add_ac) + also have "\ = (\ x. Ifm (x#bs) p)" + by (simp only: real_ex_int_real01[where P="\ x. Ifm (x#bs) p"]) + finally show ?thesis by simp +qed + + (* Implement the right hand sides of Cooper's theorem and Ferrante and Rackoff. *) + +constdefs ferrack01:: "fm \ fm" + "ferrack01 p \ (let p' = rlfm(And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p); + U = remdups(map simp_num_pair + (map (\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) + (alluopairs (\ p')))) + in decr (evaldjf (\ p') U ))" + +lemma fr_eq_01: + assumes qf: "qfree p" + shows "(\ x. Ifm (x#bs) (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)) = (\ (t,n) \ set (\ (rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p))). \ (s,m) \ set (\ (rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p))). Ifm (x#bs) (\ (rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)) (Add (Mul m t) (Mul n s), 2*n*m)))" + (is "(\ x. ?I x ?q) = ?F") +proof- + let ?rq = "rlfm ?q" + let ?M = "?I x (minusinf ?rq)" + let ?P = "?I x (plusinf ?rq)" + have MF: "?M = False" + apply (simp add: Let_def reducecoeff_def numgcd_def zgcd_def rsplit_def ge_def lt_def conj_def disj_def) + by (cases "rlfm p = And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C -1)))", simp_all) + have PF: "?P = False" apply (simp add: Let_def reducecoeff_def numgcd_def zgcd_def rsplit_def ge_def lt_def conj_def disj_def) + by (cases "rlfm p = And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C -1)))", simp_all) + have "(\ x. ?I x ?q ) = + ((?I x (minusinf ?rq)) \ (?I x (plusinf ?rq )) \ (\ (t,n) \ set (\ ?rq). \ (s,m) \ set (\ ?rq ). ?I x (\ ?rq (Add (Mul m t) (Mul n s), 2*n*m))))" + (is "(\ x. ?I x ?q) = (?M \ ?P \ ?F)" is "?E = ?D") + proof + assume "\ x. ?I x ?q" + then obtain x where qx: "?I x ?q" by blast + hence xp: "0\ x" and x1: "x< 1" and px: "?I x p" + by (auto simp add: rsplit_def lt_def ge_def rlfm_I[OF qf]) + from qx have "?I x ?rq " + by (simp add: rsplit_def lt_def ge_def rlfm_I[OF qf xp x1]) + hence lqx: "?I x ?rq " using simpfm[where p="?rq" and bs="x#bs"] by auto + from qf have qfq:"isrlfm ?rq" + by (auto simp add: rsplit_def lt_def ge_def rlfm_I[OF qf xp x1]) + with lqx fr_eq\[OF qfq] show "?M \ ?P \ ?F" by blast + next + assume D: "?D" + let ?U = "set (\ ?rq )" + from MF PF D have "?F" by auto + then obtain t n s m where aU:"(t,n) \ ?U" and bU:"(s,m)\ ?U" and rqx: "?I x (\ ?rq (Add (Mul m t) (Mul n s), 2*n*m))" by blast + from qf have lrq:"isrlfm ?rq"using rlfm_l[OF qf] + by (auto simp add: rsplit_def lt_def ge_def) + from aU bU \_l[OF lrq] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0" by (auto simp add: split_def) + let ?st = "Add (Mul m t) (Mul n s)" + from tnb snb have stnb: "numbound0 ?st" by simp + from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" + by (simp add: mult_commute) + from conjunct1[OF \_I[OF lrq mnp stnb, where bs="bs" and x="x"], symmetric] rqx + have "\ x. ?I x ?rq" by auto + thus "?E" + using rlfm_I[OF qf] by (auto simp add: rsplit_def lt_def ge_def) + qed + with MF PF show ?thesis by blast +qed + +lemma \_cong_aux: + assumes Ul: "\ (t,n) \ set U. numbound0 t \ n >0" + shows "((\ (t,n). Inum (x#bs) t /real n) ` (set (map (\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) (alluopairs U)))) = ((\ ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (set U \ set U))" + (is "?lhs = ?rhs") +proof(auto) + fix t n s m + assume "((t,n),(s,m)) \ set (alluopairs U)" + hence th: "((t,n),(s,m)) \ (set U \ set U)" + using alluopairs_set1[where xs="U"] by blast + let ?N = "\ t. Inum (x#bs) t" + let ?st= "Add (Mul m t) (Mul n s)" + from Ul th have mnz: "m \ 0" by auto + from Ul th have nnz: "n \ 0" by auto + have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" + using mnz nnz by (simp add: algebra_simps add_divide_distrib) + + thus "(real m * Inum (x # bs) t + real n * Inum (x # bs) s) / + (2 * real n * real m) + \ (\((t, n), s, m). + (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` + (set U \ set U)"using mnz nnz th + apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def) + by (rule_tac x="(s,m)" in bexI,simp_all) + (rule_tac x="(t,n)" in bexI,simp_all) +next + fix t n s m + assume tnU: "(t,n) \ set U" and smU:"(s,m) \ set U" + let ?N = "\ t. Inum (x#bs) t" + let ?st= "Add (Mul m t) (Mul n s)" + from Ul smU have mnz: "m \ 0" by auto + from Ul tnU have nnz: "n \ 0" by auto + have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" + using mnz nnz by (simp add: algebra_simps add_divide_distrib) + let ?P = "\ (t',n') (s',m'). (Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" + have Pc:"\ a b. ?P a b = ?P b a" + by auto + from Ul alluopairs_set1 have Up:"\ ((t,n),(s,m)) \ set (alluopairs U). n \ 0 \ m \ 0" by blast + from alluopairs_ex[OF Pc, where xs="U"] tnU smU + have th':"\ ((t',n'),(s',m')) \ set (alluopairs U). ?P (t',n') (s',m')" + by blast + then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \ set (alluopairs U)" + and Pts': "?P (t',n') (s',m')" by blast + from ts'_U Up have mnz': "m' \ 0" and nnz': "n'\ 0" by auto + let ?st' = "Add (Mul m' t') (Mul n' s')" + have st': "(?N t' / real n' + ?N s' / real m')/2 = ?N ?st' / real (2*n'*m')" + using mnz' nnz' by (simp add: algebra_simps add_divide_distrib) + from Pts' have + "(Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" by simp + also have "\ = ((\(t, n). Inum (x # bs) t / real n) ((\((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ((t',n'),(s',m'))))" by (simp add: st') + finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2 + \ (\(t, n). Inum (x # bs) t / real n) ` + (\((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ` + set (alluopairs U)" + using ts'_U by blast +qed + +lemma \_cong: + assumes lp: "isrlfm p" + and UU': "((\ (t,n). Inum (x#bs) t /real n) ` U') = ((\ ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (U \ U))" (is "?f ` U' = ?g ` (U\U)") + and U: "\ (t,n) \ U. numbound0 t \ n > 0" + and U': "\ (t,n) \ U'. numbound0 t \ n > 0" + shows "(\ (t,n) \ U. \ (s,m) \ U. Ifm (x#bs) (\ p (Add (Mul m t) (Mul n s),2*n*m))) = (\ (t,n) \ U'. Ifm (x#bs) (\ p (t,n)))" + (is "?lhs = ?rhs") +proof + assume ?lhs + then obtain t n s m where tnU: "(t,n) \ U" and smU:"(s,m) \ U" and + Pst: "Ifm (x#bs) (\ p (Add (Mul m t) (Mul n s),2*n*m))" by blast + let ?N = "\ t. Inum (x#bs) t" + from tnU smU U have tnb: "numbound0 t" and np: "n > 0" + and snb: "numbound0 s" and mp:"m > 0" by auto + let ?st= "Add (Mul m t) (Mul n s)" + from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" + by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) + from tnb snb have stnb: "numbound0 ?st" by simp + have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" + using mp np by (simp add: algebra_simps add_divide_distrib) + from tnU smU UU' have "?g ((t,n),(s,m)) \ ?f ` U'" by blast + hence "\ (t',n') \ U'. ?g ((t,n),(s,m)) = ?f (t',n')" + by auto (rule_tac x="(a,b)" in bexI, auto) + then obtain t' n' where tnU': "(t',n') \ U'" and th: "?g ((t,n),(s,m)) = ?f (t',n')" by blast + from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto + from \_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst + have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp + from conjunct1[OF \_I[OF lp np' tnb', where bs="bs" and x="x"], symmetric] th[simplified split_def fst_conv snd_conv,symmetric] Pst2[simplified st[symmetric]] + have "Ifm (x # bs) (\ p (t', n')) " by (simp only: st) + then show ?rhs using tnU' by auto +next + assume ?rhs + then obtain t' n' where tnU': "(t',n') \ U'" and Pt': "Ifm (x # bs) (\ p (t', n'))" + by blast + from tnU' UU' have "?f (t',n') \ ?g ` (U\U)" by blast + hence "\ ((t,n),(s,m)) \ (U\U). ?f (t',n') = ?g ((t,n),(s,m))" + by auto (rule_tac x="(a,b)" in bexI, auto) + then obtain t n s m where tnU: "(t,n) \ U" and smU:"(s,m) \ U" and + th: "?f (t',n') = ?g((t,n),(s,m)) "by blast + let ?N = "\ t. Inum (x#bs) t" + from tnU smU U have tnb: "numbound0 t" and np: "n > 0" + and snb: "numbound0 s" and mp:"m > 0" by auto + let ?st= "Add (Mul m t) (Mul n s)" + from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" + by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) + from tnb snb have stnb: "numbound0 ?st" by simp + have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" + using mp np by (simp add: algebra_simps add_divide_distrib) + from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto + from \_I[OF lp np' tnb', where bs="bs" and x="x",simplified th[simplified split_def fst_conv snd_conv] st] Pt' + have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp + with \_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU show ?lhs by blast +qed + +lemma ferrack01: + assumes qf: "qfree p" + shows "((\ x. Ifm (x#bs) (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)) = (Ifm bs (ferrack01 p))) \ qfree (ferrack01 p)" (is "(?lhs = ?rhs) \ _") +proof- + let ?I = "\ x p. Ifm (x#bs) p" + fix x + let ?N = "\ t. Inum (x#bs) t" + let ?q = "rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)" + let ?U = "\ ?q" + let ?Up = "alluopairs ?U" + let ?g = "\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)" + let ?S = "map ?g ?Up" + let ?SS = "map simp_num_pair ?S" + let ?Y = "remdups ?SS" + let ?f= "(\ (t,n). ?N t / real n)" + let ?h = "\ ((t,n),(s,m)). (?N t/real n + ?N s/ real m) /2" + let ?F = "\ p. \ a \ set (\ p). \ b \ set (\ p). ?I x (\ p (?g(a,b)))" + let ?ep = "evaldjf (\ ?q) ?Y" + from rlfm_l[OF qf] have lq: "isrlfm ?q" + by (simp add: rsplit_def lt_def ge_def conj_def disj_def Let_def reducecoeff_def numgcd_def zgcd_def) + from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \ (set ?U \ set ?U)" by simp + from \_l[OF lq] have U_l: "\ (t,n) \ set ?U. numbound0 t \ n > 0" . + from U_l UpU + have Up_: "\ ((t,n),(s,m)) \ set ?Up. numbound0 t \ n> 0 \ numbound0 s \ m > 0" by auto + hence Snb: "\ (t,n) \ set ?S. numbound0 t \ n > 0 " + by (auto simp add: mult_pos_pos) + have Y_l: "\ (t,n) \ set ?Y. numbound0 t \ n > 0" + proof- + { fix t n assume tnY: "(t,n) \ set ?Y" + hence "(t,n) \ set ?SS" by simp + hence "\ (t',n') \ set ?S. simp_num_pair (t',n') = (t,n)" + by (auto simp add: split_def) (rule_tac x="((aa,ba),(ab,bb))" in bexI, simp_all) + then obtain t' n' where tn'S: "(t',n') \ set ?S" and tns: "simp_num_pair (t',n') = (t,n)" by blast + from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" by auto + from simp_num_pair_l[OF tnb np tns] + have "numbound0 t \ n > 0" . } + thus ?thesis by blast + qed + + have YU: "(?f ` set ?Y) = (?h ` (set ?U \ set ?U))" + proof- + from simp_num_pair_ci[where bs="x#bs"] have + "\x. (?f o simp_num_pair) x = ?f x" by auto + hence th: "?f o simp_num_pair = ?f" using ext by blast + have "(?f ` set ?Y) = ((?f o simp_num_pair) ` set ?S)" by (simp add: image_compose) + also have "\ = (?f ` set ?S)" by (simp add: th) + also have "\ = ((?f o ?g) ` set ?Up)" + by (simp only: set_map o_def image_compose[symmetric]) + also have "\ = (?h ` (set ?U \ set ?U))" + using \_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_compose[symmetric]] by blast + finally show ?thesis . + qed + have "\ (t,n) \ set ?Y. bound0 (\ ?q (t,n))" + proof- + { fix t n assume tnY: "(t,n) \ set ?Y" + with Y_l have tnb: "numbound0 t" and np: "real n > 0" by auto + from \_I[OF lq np tnb] + have "bound0 (\ ?q (t,n))" by simp} + thus ?thesis by blast + qed + hence ep_nb: "bound0 ?ep" using evaldjf_bound0[where xs="?Y" and f="\ ?q"] + by auto + + from fr_eq_01[OF qf, where bs="bs" and x="x"] have "?lhs = ?F ?q" + by (simp only: split_def fst_conv snd_conv) + also have "\ = (\ (t,n) \ set ?Y. ?I x (\ ?q (t,n)))" using \_cong[OF lq YU U_l Y_l] + by (simp only: split_def fst_conv snd_conv) + also have "\ = (Ifm (x#bs) ?ep)" + using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="\ ?q",symmetric] + by (simp only: split_def pair_collapse) + also have "\ = (Ifm bs (decr ?ep))" using decr[OF ep_nb] by blast + finally have lr: "?lhs = ?rhs" by (simp only: ferrack01_def Let_def) + from decr_qf[OF ep_nb] have "qfree (ferrack01 p)" by (simp only: Let_def ferrack01_def) + with lr show ?thesis by blast +qed + +lemma cp_thm': + assumes lp: "iszlfm p (real (i::int)#bs)" + and up: "d\ p 1" and dd: "d\ p d" and dp: "d > 0" + shows "(\ (x::int). Ifm (real x#bs) p) = ((\ j\ {1 .. d}. Ifm (real j#bs) (minusinf p)) \ (\ j\ {1.. d}. \ b\ (Inum (real i#bs)) ` set (\ p). Ifm ((b+real j)#bs) p))" + using cp_thm[OF lp up dd dp] by auto + +constdefs unit:: "fm \ fm \ num list \ int" + "unit p \ (let p' = zlfm p ; l = \ p' ; q = And (Dvd l (CN 0 1 (C 0))) (a\ p' l); d = \ q; + B = remdups (map simpnum (\ q)) ; a = remdups (map simpnum (\ q)) + in if length B \ length a then (q,B,d) else (mirror q, a,d))" + +lemma unit: assumes qf: "qfree p" + shows "\ q B d. unit p = (q,B,d) \ ((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ (Inum (real i#bs)) ` set B = (Inum (real i#bs)) ` set (\ q) \ d\ q 1 \ d\ q d \ d >0 \ iszlfm q (real (i::int)#bs) \ (\ b\ set B. numbound0 b)" +proof- + fix q B d + assume qBd: "unit p = (q,B,d)" + let ?thes = "((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ + Inum (real i#bs) ` set B = Inum (real i#bs) ` set (\ q) \ + d\ q 1 \ d\ q d \ 0 < d \ iszlfm q (real i # bs) \ (\ b\ set B. numbound0 b)" + let ?I = "\ (x::int) p. Ifm (real x#bs) p" + let ?p' = "zlfm p" + let ?l = "\ ?p'" + let ?q = "And (Dvd ?l (CN 0 1 (C 0))) (a\ ?p' ?l)" + let ?d = "\ ?q" + let ?B = "set (\ ?q)" + let ?B'= "remdups (map simpnum (\ ?q))" + let ?A = "set (\ ?q)" + let ?A'= "remdups (map simpnum (\ ?q))" + from conjunct1[OF zlfm_I[OF qf, where bs="bs"]] + have pp': "\ i. ?I i ?p' = ?I i p" by auto + from iszlfm_gen[OF conjunct2[OF zlfm_I[OF qf, where bs="bs" and i="i"]]] + have lp': "\ (i::int). iszlfm ?p' (real i#bs)" by simp + hence lp'': "iszlfm ?p' (real (i::int)#bs)" by simp + from lp' \[where p="?p'" and bs="bs"] have lp: "?l >0" and dl: "d\ ?p' ?l" by auto + from a\_ex[where p="?p'" and l="?l" and bs="bs", OF lp'' dl lp] pp' + have pq_ex:"(\ (x::int). ?I x p) = (\ x. ?I x ?q)" by (simp add: int_rdvd_iff) + from lp'' lp a\[OF lp'' dl lp] have lq:"iszlfm ?q (real i#bs)" and uq: "d\ ?q 1" + by (auto simp add: isint_def) + from \[OF lq] have dp:"?d >0" and dd: "d\ ?q ?d" by blast+ + let ?N = "\ t. Inum (real (i::int)#bs) t" + have "?N ` set ?B' = ((?N o simpnum) ` ?B)" by (simp add:image_compose) + also have "\ = ?N ` ?B" using simpnum_ci[where bs="real i #bs"] by auto + finally have BB': "?N ` set ?B' = ?N ` ?B" . + have "?N ` set ?A' = ((?N o simpnum) ` ?A)" by (simp add:image_compose) + also have "\ = ?N ` ?A" using simpnum_ci[where bs="real i #bs"] by auto + finally have AA': "?N ` set ?A' = ?N ` ?A" . + from \_numbound0[OF lq] have B_nb:"\ b\ set ?B'. numbound0 b" + by (simp add: simpnum_numbound0) + from \_l[OF lq] have A_nb: "\ b\ set ?A'. numbound0 b" + by (simp add: simpnum_numbound0) + {assume "length ?B' \ length ?A'" + hence q:"q=?q" and "B = ?B'" and d:"d = ?d" + using qBd by (auto simp add: Let_def unit_def) + with BB' B_nb have b: "?N ` (set B) = ?N ` set (\ q)" + and bn: "\b\ set B. numbound0 b" by simp+ + with pq_ex dp uq dd lq q d have ?thes by simp} + moreover + {assume "\ (length ?B' \ length ?A')" + hence q:"q=mirror ?q" and "B = ?A'" and d:"d = ?d" + using qBd by (auto simp add: Let_def unit_def) + with AA' mirror\\[OF lq] A_nb have b:"?N ` (set B) = ?N ` set (\ q)" + and bn: "\b\ set B. numbound0 b" by simp+ + from mirror_ex[OF lq] pq_ex q + have pqm_eq:"(\ (x::int). ?I x p) = (\ (x::int). ?I x q)" by simp + from lq uq q mirror_d\ [where p="?q" and bs="bs" and a="real i"] + have lq': "iszlfm q (real i#bs)" and uq: "d\ q 1" by auto + from \[OF lq'] mirror_\[OF lq] q d have dq:"d\ q d " by auto + from pqm_eq b bn uq lq' dp dq q dp d have ?thes by simp + } + ultimately show ?thes by blast +qed + (* Cooper's Algorithm *) + +constdefs cooper :: "fm \ fm" + "cooper p \ + (let (q,B,d) = unit p; js = iupt (1,d); + mq = simpfm (minusinf q); + md = evaldjf (\ j. simpfm (subst0 (C j) mq)) js + in if md = T then T else + (let qd = evaldjf (\ t. simpfm (subst0 t q)) + (remdups (map (\ (b,j). simpnum (Add b (C j))) + [(b,j). b\B,j\js])) + in decr (disj md qd)))" +lemma cooper: assumes qf: "qfree p" + shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (cooper p))) \ qfree (cooper p)" + (is "(?lhs = ?rhs) \ _") +proof- + + let ?I = "\ (x::int) p. Ifm (real x#bs) p" + let ?q = "fst (unit p)" + let ?B = "fst (snd(unit p))" + let ?d = "snd (snd (unit p))" + let ?js = "iupt (1,?d)" + let ?mq = "minusinf ?q" + let ?smq = "simpfm ?mq" + let ?md = "evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js" + fix i + let ?N = "\ t. Inum (real (i::int)#bs) t" + let ?bjs = "[(b,j). b\?B,j\?js]" + let ?sbjs = "map (\ (b,j). simpnum (Add b (C j))) ?bjs" + let ?qd = "evaldjf (\ t. simpfm (subst0 t ?q)) (remdups ?sbjs)" + have qbf:"unit p = (?q,?B,?d)" by simp + from unit[OF qf qbf] have pq_ex: "(\(x::int). ?I x p) = (\ (x::int). ?I x ?q)" and + B:"?N ` set ?B = ?N ` set (\ ?q)" and + uq:"d\ ?q 1" and dd: "d\ ?q ?d" and dp: "?d > 0" and + lq: "iszlfm ?q (real i#bs)" and + Bn: "\ b\ set ?B. numbound0 b" by auto + from zlin_qfree[OF lq] have qfq: "qfree ?q" . + from simpfm_qf[OF minusinf_qfree[OF qfq]] have qfmq: "qfree ?smq". + have jsnb: "\ j \ set ?js. numbound0 (C j)" by simp + hence "\ j\ set ?js. bound0 (subst0 (C j) ?smq)" + by (auto simp only: subst0_bound0[OF qfmq]) + hence th: "\ j\ set ?js. bound0 (simpfm (subst0 (C j) ?smq))" + by (auto simp add: simpfm_bound0) + from evaldjf_bound0[OF th] have mdb: "bound0 ?md" by simp + from Bn jsnb have "\ (b,j) \ set ?bjs. numbound0 (Add b (C j))" + by simp + hence "\ (b,j) \ set ?bjs. numbound0 (simpnum (Add b (C j)))" + using simpnum_numbound0 by blast + hence "\ t \ set ?sbjs. numbound0 t" by simp + hence "\ t \ set (remdups ?sbjs). bound0 (subst0 t ?q)" + using subst0_bound0[OF qfq] by auto + hence th': "\ t \ set (remdups ?sbjs). bound0 (simpfm (subst0 t ?q))" + using simpfm_bound0 by blast + from evaldjf_bound0 [OF th'] have qdb: "bound0 ?qd" by simp + from mdb qdb + have mdqdb: "bound0 (disj ?md ?qd)" by (simp only: disj_def, cases "?md=T \ ?qd=T", simp_all) + from trans [OF pq_ex cp_thm'[OF lq uq dd dp]] B + have "?lhs = (\ j\ {1.. ?d}. ?I j ?mq \ (\ b\ ?N ` set ?B. Ifm ((b+ real j)#bs) ?q))" by auto + also have "\ = ((\ j\ set ?js. ?I j ?smq) \ (\ (b,j) \ (?N ` set ?B \ set ?js). Ifm ((b+ real j)#bs) ?q))" apply (simp only: iupt_set simpfm) by auto + also have "\= ((\ j\ set ?js. ?I j ?smq) \ (\ t \ (\ (b,j). ?N (Add b (C j))) ` set ?bjs. Ifm (t #bs) ?q))" by simp + also have "\= ((\ j\ set ?js. ?I j ?smq) \ (\ t \ (\ (b,j). ?N (simpnum (Add b (C j)))) ` set ?bjs. Ifm (t #bs) ?q))" by (simp only: simpnum_ci) + also have "\= ((\ j\ set ?js. ?I j ?smq) \ (\ t \ set ?sbjs. Ifm (?N t #bs) ?q))" + by (auto simp add: split_def) + also have "\ = ((\ j\ set ?js. (\ j. ?I i (simpfm (subst0 (C j) ?smq))) j) \ (\ t \ set (remdups ?sbjs). (\ t. ?I i (simpfm (subst0 t ?q))) t))" by (simp only: simpfm subst0_I[OF qfq] simpfm Inum.simps subst0_I[OF qfmq] set_remdups) + also have "\ = ((?I i (evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js)) \ (?I i (evaldjf (\ t. simpfm (subst0 t ?q)) (remdups ?sbjs))))" by (simp only: evaldjf_ex) + finally have mdqd: "?lhs = (?I i (disj ?md ?qd))" by (simp add: disj) + hence mdqd2: "?lhs = (Ifm bs (decr (disj ?md ?qd)))" using decr [OF mdqdb] by simp + {assume mdT: "?md = T" + hence cT:"cooper p = T" + by (simp only: cooper_def unit_def split_def Let_def if_True) simp + from mdT mdqd have lhs:"?lhs" by (auto simp add: disj) + from mdT have "?rhs" by (simp add: cooper_def unit_def split_def) + with lhs cT have ?thesis by simp } + moreover + {assume mdT: "?md \ T" hence "cooper p = decr (disj ?md ?qd)" + by (simp only: cooper_def unit_def split_def Let_def if_False) + with mdqd2 decr_qf[OF mdqdb] have ?thesis by simp } + ultimately show ?thesis by blast +qed + +lemma DJcooper: + assumes qf: "qfree p" + shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (DJ cooper p))) \ qfree (DJ cooper p)" +proof- + from cooper have cqf: "\ p. qfree p \ qfree (cooper p)" by blast + from DJ_qf[OF cqf] qf have thqf:"qfree (DJ cooper p)" by blast + have "Ifm bs (DJ cooper p) = (\ q\ set (disjuncts p). Ifm bs (cooper q))" + by (simp add: DJ_def evaldjf_ex) + also have "\ = (\ q \ set(disjuncts p). \ (x::int). Ifm (real x#bs) q)" + using cooper disjuncts_qf[OF qf] by blast + also have "\ = (\ (x::int). Ifm (real x#bs) p)" by (induct p rule: disjuncts.induct, auto) + finally show ?thesis using thqf by blast +qed + + (* Redy and Loveland *) + +lemma \\_cong: assumes lp: "iszlfm p (a#bs)" and tt': "Inum (a#bs) t = Inum (a#bs) t'" + shows "Ifm (a#bs) (\\ p (t,c)) = Ifm (a#bs) (\\ p (t',c))" + using lp + by (induct p rule: iszlfm.induct, auto simp add: tt') + +lemma \_cong: assumes lp: "iszlfm p (a#bs)" and tt': "Inum (a#bs) t = Inum (a#bs) t'" + shows "Ifm (a#bs) (\ p c t) = Ifm (a#bs) (\ p c t')" + by (simp add: \_def tt' \\_cong[OF lp tt']) + +lemma \_cong: assumes lp: "iszlfm p (a#bs)" + and RR: "(\(b,k). (Inum (a#bs) b,k)) ` R = (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" + shows "(\ (e,c) \ R. \ j\ {1.. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j)))) = (\ (e,c) \ set (\ p). \ j\ {1.. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j))))" + (is "?lhs = ?rhs") +proof + let ?d = "\ p" + assume ?lhs then obtain e c j where ecR: "(e,c) \ R" and jD:"j \ {1 .. c*?d}" + and px: "Ifm (a#bs) (\ p c (Add e (C j)))" (is "?sp c e j") by blast + from ecR have "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` R" by auto + hence "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" using RR by simp + hence "\ (e',c') \ set (\ p). Inum (a#bs) e = Inum (a#bs) e' \ c = c'" by auto + then obtain e' c' where ecRo:"(e',c') \ set (\ p)" and ee':"Inum (a#bs) e = Inum (a#bs) e'" + and cc':"c = c'" by blast + from ee' have tt': "Inum (a#bs) (Add e (C j)) = Inum (a#bs) (Add e' (C j))" by simp + + from \_cong[OF lp tt', where c="c"] px have px':"?sp c e' j" by simp + from ecRo jD px' cc' show ?rhs apply auto + by (rule_tac x="(e', c')" in bexI,simp_all) + (rule_tac x="j" in bexI, simp_all add: cc'[symmetric]) +next + let ?d = "\ p" + assume ?rhs then obtain e c j where ecR: "(e,c) \ set (\ p)" and jD:"j \ {1 .. c*?d}" + and px: "Ifm (a#bs) (\ p c (Add e (C j)))" (is "?sp c e j") by blast + from ecR have "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" by auto + hence "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` R" using RR by simp + hence "\ (e',c') \ R. Inum (a#bs) e = Inum (a#bs) e' \ c = c'" by auto + then obtain e' c' where ecRo:"(e',c') \ R" and ee':"Inum (a#bs) e = Inum (a#bs) e'" + and cc':"c = c'" by blast + from ee' have tt': "Inum (a#bs) (Add e (C j)) = Inum (a#bs) (Add e' (C j))" by simp + from \_cong[OF lp tt', where c="c"] px have px':"?sp c e' j" by simp + from ecRo jD px' cc' show ?lhs apply auto + by (rule_tac x="(e', c')" in bexI,simp_all) + (rule_tac x="j" in bexI, simp_all add: cc'[symmetric]) +qed + +lemma rl_thm': + assumes lp: "iszlfm p (real (i::int)#bs)" + and R: "(\(b,k). (Inum (a#bs) b,k)) ` R = (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" + shows "(\ (x::int). Ifm (real x#bs) p) = ((\ j\ {1 .. \ p}. Ifm (real j#bs) (minusinf p)) \ (\ (e,c) \ R. \ j\ {1.. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j)))))" + using rl_thm[OF lp] \_cong[OF iszlfm_gen[OF lp, rule_format, where y="a"] R] by simp + +constdefs chooset:: "fm \ fm \ ((num\int) list) \ int" + "chooset p \ (let q = zlfm p ; d = \ q; + B = remdups (map (\ (t,k). (simpnum t,k)) (\ q)) ; + a = remdups (map (\ (t,k). (simpnum t,k)) (\\ q)) + in if length B \ length a then (q,B,d) else (mirror q, a,d))" + +lemma chooset: assumes qf: "qfree p" + shows "\ q B d. chooset p = (q,B,d) \ ((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ ((\(t,k). (Inum (real i#bs) t,k)) ` set B = (\(t,k). (Inum (real i#bs) t,k)) ` set (\ q)) \ (\ q = d) \ d >0 \ iszlfm q (real (i::int)#bs) \ (\ (e,c)\ set B. numbound0 e \ c>0)" +proof- + fix q B d + assume qBd: "chooset p = (q,B,d)" + let ?thes = "((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ ((\(t,k). (Inum (real i#bs) t,k)) ` set B = (\(t,k). (Inum (real i#bs) t,k)) ` set (\ q)) \ (\ q = d) \ d >0 \ iszlfm q (real (i::int)#bs) \ (\ (e,c)\ set B. numbound0 e \ c>0)" + let ?I = "\ (x::int) p. Ifm (real x#bs) p" + let ?q = "zlfm p" + let ?d = "\ ?q" + let ?B = "set (\ ?q)" + let ?f = "\ (t,k). (simpnum t,k)" + let ?B'= "remdups (map ?f (\ ?q))" + let ?A = "set (\\ ?q)" + let ?A'= "remdups (map ?f (\\ ?q))" + from conjunct1[OF zlfm_I[OF qf, where bs="bs"]] + have pp': "\ i. ?I i ?q = ?I i p" by auto + hence pq_ex:"(\ (x::int). ?I x p) = (\ x. ?I x ?q)" by simp + from iszlfm_gen[OF conjunct2[OF zlfm_I[OF qf, where bs="bs" and i="i"]], rule_format, where y="real i"] + have lq: "iszlfm ?q (real (i::int)#bs)" . + from \[OF lq] have dp:"?d >0" by blast + let ?N = "\ (t,c). (Inum (real (i::int)#bs) t,c)" + have "?N ` set ?B' = ((?N o ?f) ` ?B)" by (simp add: split_def image_compose) + also have "\ = ?N ` ?B" + by(simp add: split_def image_compose simpnum_ci[where bs="real i #bs"] image_def) + finally have BB': "?N ` set ?B' = ?N ` ?B" . + have "?N ` set ?A' = ((?N o ?f) ` ?A)" by (simp add: split_def image_compose) + also have "\ = ?N ` ?A" using simpnum_ci[where bs="real i #bs"] + by(simp add: split_def image_compose simpnum_ci[where bs="real i #bs"] image_def) + finally have AA': "?N ` set ?A' = ?N ` ?A" . + from \_l[OF lq] have B_nb:"\ (e,c)\ set ?B'. numbound0 e \ c > 0" + by (simp add: simpnum_numbound0 split_def) + from \\_l[OF lq] have A_nb: "\ (e,c)\ set ?A'. numbound0 e \ c > 0" + by (simp add: simpnum_numbound0 split_def) + {assume "length ?B' \ length ?A'" + hence q:"q=?q" and "B = ?B'" and d:"d = ?d" + using qBd by (auto simp add: Let_def chooset_def) + with BB' B_nb have b: "?N ` (set B) = ?N ` set (\ q)" + and bn: "\(e,c)\ set B. numbound0 e \ c > 0" by auto + with pq_ex dp lq q d have ?thes by simp} + moreover + {assume "\ (length ?B' \ length ?A')" + hence q:"q=mirror ?q" and "B = ?A'" and d:"d = ?d" + using qBd by (auto simp add: Let_def chooset_def) + with AA' mirror_\\[OF lq] A_nb have b:"?N ` (set B) = ?N ` set (\ q)" + and bn: "\(e,c)\ set B. numbound0 e \ c > 0" by auto + from mirror_ex[OF lq] pq_ex q + have pqm_eq:"(\ (x::int). ?I x p) = (\ (x::int). ?I x q)" by simp + from lq q mirror_l [where p="?q" and bs="bs" and a="real i"] + have lq': "iszlfm q (real i#bs)" by auto + from mirror_\[OF lq] pqm_eq b bn lq' dp q dp d have ?thes by simp + } + ultimately show ?thes by blast +qed + +constdefs stage:: "fm \ int \ (num \ int) \ fm" + "stage p d \ (\ (e,c). evaldjf (\ j. simpfm (\ p c (Add e (C j)))) (iupt (1,c*d)))" +lemma stage: + shows "Ifm bs (stage p d (e,c)) = (\ j\{1 .. c*d}. Ifm bs (\ p c (Add e (C j))))" + by (unfold stage_def split_def ,simp only: evaldjf_ex iupt_set simpfm) simp + +lemma stage_nb: assumes lp: "iszlfm p (a#bs)" and cp: "c >0" and nb:"numbound0 e" + shows "bound0 (stage p d (e,c))" +proof- + let ?f = "\ j. simpfm (\ p c (Add e (C j)))" + have th: "\ j\ set (iupt(1,c*d)). bound0 (?f j)" + proof + fix j + from nb have nb':"numbound0 (Add e (C j))" by simp + from simpfm_bound0[OF \_nb[OF lp nb', where k="c"]] + show "bound0 (simpfm (\ p c (Add e (C j))))" . + qed + from evaldjf_bound0[OF th] show ?thesis by (unfold stage_def split_def) simp +qed + +constdefs redlove:: "fm \ fm" + "redlove p \ + (let (q,B,d) = chooset p; + mq = simpfm (minusinf q); + md = evaldjf (\ j. simpfm (subst0 (C j) mq)) (iupt (1,d)) + in if md = T then T else + (let qd = evaldjf (stage q d) B + in decr (disj md qd)))" + +lemma redlove: assumes qf: "qfree p" + shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (redlove p))) \ qfree (redlove p)" + (is "(?lhs = ?rhs) \ _") +proof- + + let ?I = "\ (x::int) p. Ifm (real x#bs) p" + let ?q = "fst (chooset p)" + let ?B = "fst (snd(chooset p))" + let ?d = "snd (snd (chooset p))" + let ?js = "iupt (1,?d)" + let ?mq = "minusinf ?q" + let ?smq = "simpfm ?mq" + let ?md = "evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js" + fix i + let ?N = "\ (t,k). (Inum (real (i::int)#bs) t,k)" + let ?qd = "evaldjf (stage ?q ?d) ?B" + have qbf:"chooset p = (?q,?B,?d)" by simp + from chooset[OF qf qbf] have pq_ex: "(\(x::int). ?I x p) = (\ (x::int). ?I x ?q)" and + B:"?N ` set ?B = ?N ` set (\ ?q)" and dd: "\ ?q = ?d" and dp: "?d > 0" and + lq: "iszlfm ?q (real i#bs)" and + Bn: "\ (e,c)\ set ?B. numbound0 e \ c > 0" by auto + from zlin_qfree[OF lq] have qfq: "qfree ?q" . + from simpfm_qf[OF minusinf_qfree[OF qfq]] have qfmq: "qfree ?smq". + have jsnb: "\ j \ set ?js. numbound0 (C j)" by simp + hence "\ j\ set ?js. bound0 (subst0 (C j) ?smq)" + by (auto simp only: subst0_bound0[OF qfmq]) + hence th: "\ j\ set ?js. bound0 (simpfm (subst0 (C j) ?smq))" + by (auto simp add: simpfm_bound0) + from evaldjf_bound0[OF th] have mdb: "bound0 ?md" by simp + from Bn stage_nb[OF lq] have th:"\ x \ set ?B. bound0 (stage ?q ?d x)" by auto + from evaldjf_bound0[OF th] have qdb: "bound0 ?qd" . + from mdb qdb + have mdqdb: "bound0 (disj ?md ?qd)" by (simp only: disj_def, cases "?md=T \ ?qd=T", simp_all) + from trans [OF pq_ex rl_thm'[OF lq B]] dd + have "?lhs = ((\ j\ {1.. ?d}. ?I j ?mq) \ (\ (e,c)\ set ?B. \ j\ {1 .. c*?d}. Ifm (real i#bs) (\ ?q c (Add e (C j)))))" by auto + also have "\ = ((\ j\ {1.. ?d}. ?I j ?smq) \ (\ (e,c)\ set ?B. ?I i (stage ?q ?d (e,c) )))" + by (simp add: simpfm stage split_def) + also have "\ = ((\ j\ {1 .. ?d}. ?I i (subst0 (C j) ?smq)) \ ?I i ?qd)" + by (simp add: evaldjf_ex subst0_I[OF qfmq]) + finally have mdqd:"?lhs = (?I i ?md \ ?I i ?qd)" by (simp only: evaldjf_ex iupt_set simpfm) + also have "\ = (?I i (disj ?md ?qd))" by (simp add: disj) + also have "\ = (Ifm bs (decr (disj ?md ?qd)))" by (simp only: decr [OF mdqdb]) + finally have mdqd2: "?lhs = (Ifm bs (decr (disj ?md ?qd)))" . + {assume mdT: "?md = T" + hence cT:"redlove p = T" by (simp add: redlove_def Let_def chooset_def split_def) + from mdT have lhs:"?lhs" using mdqd by simp + from mdT have "?rhs" by (simp add: redlove_def chooset_def split_def) + with lhs cT have ?thesis by simp } + moreover + {assume mdT: "?md \ T" hence "redlove p = decr (disj ?md ?qd)" + by (simp add: redlove_def chooset_def split_def Let_def) + with mdqd2 decr_qf[OF mdqdb] have ?thesis by simp } + ultimately show ?thesis by blast +qed + +lemma DJredlove: + assumes qf: "qfree p" + shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (DJ redlove p))) \ qfree (DJ redlove p)" +proof- + from redlove have cqf: "\ p. qfree p \ qfree (redlove p)" by blast + from DJ_qf[OF cqf] qf have thqf:"qfree (DJ redlove p)" by blast + have "Ifm bs (DJ redlove p) = (\ q\ set (disjuncts p). Ifm bs (redlove q))" + by (simp add: DJ_def evaldjf_ex) + also have "\ = (\ q \ set(disjuncts p). \ (x::int). Ifm (real x#bs) q)" + using redlove disjuncts_qf[OF qf] by blast + also have "\ = (\ (x::int). Ifm (real x#bs) p)" by (induct p rule: disjuncts.induct, auto) + finally show ?thesis using thqf by blast +qed + + +lemma exsplit_qf: assumes qf: "qfree p" + shows "qfree (exsplit p)" +using qf by (induct p rule: exsplit.induct, auto) + +definition mircfr :: "fm \ fm" where + "mircfr = DJ cooper o ferrack01 o simpfm o exsplit" + +definition mirlfr :: "fm \ fm" where + "mirlfr = DJ redlove o ferrack01 o simpfm o exsplit" + +lemma mircfr: "\ bs p. qfree p \ qfree (mircfr p) \ Ifm bs (mircfr p) = Ifm bs (E p)" +proof(clarsimp simp del: Ifm.simps) + fix bs p + assume qf: "qfree p" + show "qfree (mircfr p)\(Ifm bs (mircfr p) = Ifm bs (E p))" (is "_ \ (?lhs = ?rhs)") + proof- + let ?es = "(And (And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) (simpfm (exsplit p)))" + have "?rhs = (\ (i::int). \ x. Ifm (x#real i#bs) ?es)" + using splitex[OF qf] by simp + with ferrack01[OF simpfm_qf[OF exsplit_qf[OF qf]]] have th1: "?rhs = (\ (i::int). Ifm (real i#bs) (ferrack01 (simpfm (exsplit p))))" and qf':"qfree (ferrack01 (simpfm (exsplit p)))" by simp+ + with DJcooper[OF qf'] show ?thesis by (simp add: mircfr_def) + qed +qed + +lemma mirlfr: "\ bs p. qfree p \ qfree(mirlfr p) \ Ifm bs (mirlfr p) = Ifm bs (E p)" +proof(clarsimp simp del: Ifm.simps) + fix bs p + assume qf: "qfree p" + show "qfree (mirlfr p)\(Ifm bs (mirlfr p) = Ifm bs (E p))" (is "_ \ (?lhs = ?rhs)") + proof- + let ?es = "(And (And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) (simpfm (exsplit p)))" + have "?rhs = (\ (i::int). \ x. Ifm (x#real i#bs) ?es)" + using splitex[OF qf] by simp + with ferrack01[OF simpfm_qf[OF exsplit_qf[OF qf]]] have th1: "?rhs = (\ (i::int). Ifm (real i#bs) (ferrack01 (simpfm (exsplit p))))" and qf':"qfree (ferrack01 (simpfm (exsplit p)))" by simp+ + with DJredlove[OF qf'] show ?thesis by (simp add: mirlfr_def) + qed +qed + +definition mircfrqe:: "fm \ fm" where + "mircfrqe p = qelim (prep p) mircfr" + +definition mirlfrqe:: "fm \ fm" where + "mirlfrqe p = qelim (prep p) mirlfr" + +theorem mircfrqe: "(Ifm bs (mircfrqe p) = Ifm bs p) \ qfree (mircfrqe p)" + using qelim_ci[OF mircfr] prep by (auto simp add: mircfrqe_def) + +theorem mirlfrqe: "(Ifm bs (mirlfrqe p) = Ifm bs p) \ qfree (mirlfrqe p)" + using qelim_ci[OF mirlfr] prep by (auto simp add: mirlfrqe_def) + +definition + "test1 (u\unit) = mircfrqe (A (And (Le (Sub (Floor (Bound 0)) (Bound 0))) (Le (Add (Bound 0) (Floor (Neg (Bound 0)))))))" + +definition + "test2 (u\unit) = mircfrqe (A (Iff (Eq (Add (Floor (Bound 0)) (Floor (Neg (Bound 0))))) (Eq (Sub (Floor (Bound 0)) (Bound 0)))))" + +definition + "test3 (u\unit) = mirlfrqe (A (And (Le (Sub (Floor (Bound 0)) (Bound 0))) (Le (Add (Bound 0) (Floor (Neg (Bound 0)))))))" + +definition + "test4 (u\unit) = mirlfrqe (A (Iff (Eq (Add (Floor (Bound 0)) (Floor (Neg (Bound 0))))) (Eq (Sub (Floor (Bound 0)) (Bound 0)))))" + +definition + "test5 (u\unit) = mircfrqe (A(E(And (Ge(Sub (Bound 1) (Bound 0))) (Eq (Add (Floor (Bound 1)) (Floor (Neg(Bound 0))))))))" + +ML {* @{code test1} () *} +ML {* @{code test2} () *} +ML {* @{code test3} () *} +ML {* @{code test4} () *} +ML {* @{code test5} () *} + +(*export_code mircfrqe mirlfrqe + in SML module_name Mir file "raw_mir.ML"*) + +oracle mirfr_oracle = {* fn (proofs, ct) => +let + +fun num_of_term vs (t as Free (xn, xT)) = (case AList.lookup (op =) vs t + of NONE => error "Variable not found in the list!" + | SOME n => @{code Bound} n) + | num_of_term vs @{term "real (0::int)"} = @{code C} 0 + | num_of_term vs @{term "real (1::int)"} = @{code C} 1 + | num_of_term vs @{term "0::real"} = @{code C} 0 + | num_of_term vs @{term "1::real"} = @{code C} 1 + | num_of_term vs (Bound i) = @{code Bound} i + | num_of_term vs (@{term "uminus :: real \ real"} $ t') = @{code Neg} (num_of_term vs t') + | num_of_term vs (@{term "op + :: real \ real \ real"} $ t1 $ t2) = + @{code Add} (num_of_term vs t1, num_of_term vs t2) + | num_of_term vs (@{term "op - :: real \ real \ real"} $ t1 $ t2) = + @{code Sub} (num_of_term vs t1, num_of_term vs t2) + | num_of_term vs (@{term "op * :: real \ real \ real"} $ t1 $ t2) = + (case (num_of_term vs t1) + of @{code C} i => @{code Mul} (i, num_of_term vs t2) + | _ => error "num_of_term: unsupported Multiplication") + | num_of_term vs (@{term "real :: int \ real"} $ (@{term "number_of :: int \ int"} $ t')) = + @{code C} (HOLogic.dest_numeral t') + | num_of_term vs (@{term "real :: int \ real"} $ (@{term "floor :: real \ int"} $ t')) = + @{code Floor} (num_of_term vs t') + | num_of_term vs (@{term "real :: int \ real"} $ (@{term "ceiling :: real \ int"} $ t')) = + @{code Neg} (@{code Floor} (@{code Neg} (num_of_term vs t'))) + | num_of_term vs (@{term "number_of :: int \ real"} $ t') = + @{code C} (HOLogic.dest_numeral t') + | num_of_term vs t = error ("num_of_term: unknown term " ^ Syntax.string_of_term @{context} t); + +fun fm_of_term vs @{term True} = @{code T} + | fm_of_term vs @{term False} = @{code F} + | fm_of_term vs (@{term "op < :: real \ real \ bool"} $ t1 $ t2) = + @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) + | fm_of_term vs (@{term "op \ :: real \ real \ bool"} $ t1 $ t2) = + @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) + | fm_of_term vs (@{term "op = :: real \ real \ bool"} $ t1 $ t2) = + @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) + | fm_of_term vs (@{term "op rdvd"} $ (@{term "real :: int \ real"} $ (@{term "number_of :: int \ int"} $ t1)) $ t2) = + @{code Dvd} (HOLogic.dest_numeral t1, num_of_term vs t2) + | fm_of_term vs (@{term "op = :: bool \ bool \ bool"} $ t1 $ t2) = + @{code Iff} (fm_of_term vs t1, fm_of_term vs t2) + | fm_of_term vs (@{term "op &"} $ t1 $ t2) = + @{code And} (fm_of_term vs t1, fm_of_term vs t2) + | fm_of_term vs (@{term "op |"} $ t1 $ t2) = + @{code Or} (fm_of_term vs t1, fm_of_term vs t2) + | fm_of_term vs (@{term "op -->"} $ t1 $ t2) = + @{code Imp} (fm_of_term vs t1, fm_of_term vs t2) + | fm_of_term vs (@{term "Not"} $ t') = + @{code NOT} (fm_of_term vs t') + | fm_of_term vs (Const ("Ex", _) $ Abs (xn, xT, p)) = + @{code E} (fm_of_term (map (fn (v, n) => (v, n + 1)) vs) p) + | fm_of_term vs (Const ("All", _) $ Abs (xn, xT, p)) = + @{code A} (fm_of_term (map (fn (v, n) => (v, n + 1)) vs) p) + | fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); + +fun term_of_num vs (@{code C} i) = @{term "real :: int \ real"} $ HOLogic.mk_number HOLogic.intT i + | term_of_num vs (@{code Bound} n) = fst (the (find_first (fn (_, m) => n = m) vs)) + | term_of_num vs (@{code Neg} (@{code Floor} (@{code Neg} t'))) = + @{term "real :: int \ real"} $ (@{term "ceiling :: real \ int"} $ term_of_num vs t') + | term_of_num vs (@{code Neg} t') = @{term "uminus :: real \ real"} $ term_of_num vs t' + | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \ real \ real"} $ + term_of_num vs t1 $ term_of_num vs t2 + | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \ real \ real"} $ + term_of_num vs t1 $ term_of_num vs t2 + | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \ real \ real"} $ + term_of_num vs (@{code C} i) $ term_of_num vs t2 + | term_of_num vs (@{code Floor} t) = @{term "real :: int \ real"} $ (@{term "floor :: real \ int"} $ term_of_num vs t) + | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)) + | term_of_num vs (@{code CF} (c, t, s)) = term_of_num vs (@{code Add} (@{code Mul} (c, @{code Floor} t), s)); + +fun term_of_fm vs @{code T} = HOLogic.true_const + | term_of_fm vs @{code F} = HOLogic.false_const + | term_of_fm vs (@{code Lt} t) = + @{term "op < :: real \ real \ bool"} $ term_of_num vs t $ @{term "0::real"} + | term_of_fm vs (@{code Le} t) = + @{term "op \ :: real \ real \ bool"} $ term_of_num vs t $ @{term "0::real"} + | term_of_fm vs (@{code Gt} t) = + @{term "op < :: real \ real \ bool"} $ @{term "0::real"} $ term_of_num vs t + | term_of_fm vs (@{code Ge} t) = + @{term "op \ :: real \ real \ bool"} $ @{term "0::real"} $ term_of_num vs t + | term_of_fm vs (@{code Eq} t) = + @{term "op = :: real \ real \ bool"} $ term_of_num vs t $ @{term "0::real"} + | term_of_fm vs (@{code NEq} t) = + term_of_fm vs (@{code NOT} (@{code Eq} t)) + | term_of_fm vs (@{code Dvd} (i, t)) = + @{term "op rdvd"} $ term_of_num vs (@{code C} i) $ term_of_num vs t + | term_of_fm vs (@{code NDvd} (i, t)) = + term_of_fm vs (@{code NOT} (@{code Dvd} (i, t))) + | term_of_fm vs (@{code NOT} t') = + HOLogic.Not $ term_of_fm vs t' + | term_of_fm vs (@{code And} (t1, t2)) = + HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2 + | term_of_fm vs (@{code Or} (t1, t2)) = + HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2 + | term_of_fm vs (@{code Imp} (t1, t2)) = + HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2 + | term_of_fm vs (@{code Iff} (t1, t2)) = + @{term "op = :: bool \ bool \ bool"} $ term_of_fm vs t1 $ term_of_fm vs t2; + +in + let + val thy = Thm.theory_of_cterm ct; + val t = Thm.term_of ct; + val fs = OldTerm.term_frees t; + val vs = fs ~~ (0 upto (length fs - 1)); + val qe = if proofs then @{code mirlfrqe} else @{code mircfrqe}; + val t' = (term_of_fm vs o qe o fm_of_term vs) t; + in (cterm_of thy o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end +end; +*} + +use "mir_tac.ML" +setup "Mir_Tac.setup" + +lemma "ALL (x::real). (\x\ = \x\ = (x = real \x\))" +apply mir +done + +lemma "ALL (x::real). real (2::int)*x - (real (1::int)) < real \x\ + real \x\ \ real \x\ + real \x\ \ real (2::int)*x + (real (1::int))" +apply mir +done + +lemma "ALL (x::real). 2*\x\ \ \2*x\ \ \2*x\ \ 2*\x+1\" +apply mir +done + +lemma "ALL (x::real). \y \ x. (\x\ = \y\)" +apply mir +done + +lemma "ALL x y. \x\ = \y\ \ 0 \ abs (y - x) \ abs (y - x) \ 1" +apply mir +done + +end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/Reflection/cooper_tac.ML --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Reflection/cooper_tac.ML Tue Feb 03 16:50:41 2009 +0100 @@ -0,0 +1,139 @@ +(* Title: HOL/Reflection/cooper_tac.ML + Author: Amine Chaieb, TU Muenchen +*) + +structure Cooper_Tac = +struct + +val trace = ref false; +fun trace_msg s = if !trace then tracing s else (); + +val cooper_ss = @{simpset}; + +val nT = HOLogic.natT; +val binarith = @{thms normalize_bin_simps}; +val comp_arith = binarith @ simp_thms + +val zdvd_int = @{thm zdvd_int}; +val zdiff_int_split = @{thm zdiff_int_split}; +val all_nat = @{thm all_nat}; +val ex_nat = @{thm ex_nat}; +val number_of1 = @{thm number_of1}; +val number_of2 = @{thm number_of2}; +val split_zdiv = @{thm split_zdiv}; +val split_zmod = @{thm split_zmod}; +val mod_div_equality' = @{thm mod_div_equality'}; +val split_div' = @{thm split_div'}; +val Suc_plus1 = @{thm Suc_plus1}; +val imp_le_cong = @{thm imp_le_cong}; +val conj_le_cong = @{thm conj_le_cong}; +val nat_mod_add_eq = @{thm mod_add1_eq} RS sym; +val nat_mod_add_left_eq = @{thm mod_add_left_eq} RS sym; +val nat_mod_add_right_eq = @{thm mod_add_right_eq} RS sym; +val int_mod_add_eq = @{thm zmod_zadd1_eq} RS sym; +val int_mod_add_left_eq = @{thm zmod_zadd_left_eq} RS sym; +val int_mod_add_right_eq = @{thm zmod_zadd_right_eq} RS sym; +val nat_div_add_eq = @{thm div_add1_eq} RS sym; +val int_div_add_eq = @{thm zdiv_zadd1_eq} RS sym; + +fun prepare_for_linz q fm = + let + val ps = Logic.strip_params fm + val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) + val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) + fun mk_all ((s, T), (P,n)) = + if 0 mem loose_bnos P then + (HOLogic.all_const T $ Abs (s, T, P), n) + else (incr_boundvars ~1 P, n-1) + fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; + val rhs = hs + val np = length ps + val (fm',np) = foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) + (foldr HOLogic.mk_imp c rhs, np) ps + val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT) + (OldTerm.term_frees fm' @ OldTerm.term_vars fm'); + val fm2 = foldr mk_all2 fm' vs + in (fm2, np + length vs, length rhs) end; + +(*Object quantifier to meta --*) +fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; + +(* object implication to meta---*) +fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; + + +fun linz_tac ctxt q i = ObjectLogic.atomize_prems_tac i THEN (fn st => + let + val g = List.nth (prems_of st, i - 1) + val thy = ProofContext.theory_of ctxt + (* Transform the term*) + val (t,np,nh) = prepare_for_linz q g + (* Some simpsets for dealing with mod div abs and nat*) + val mod_div_simpset = HOL_basic_ss + addsimps [refl,nat_mod_add_eq, nat_mod_add_left_eq, + nat_mod_add_right_eq, int_mod_add_eq, + int_mod_add_right_eq, int_mod_add_left_eq, + nat_div_add_eq, int_div_add_eq, + @{thm mod_self}, @{thm "zmod_self"}, + @{thm mod_by_0}, @{thm div_by_0}, + @{thm "zdiv_zero"}, @{thm "zmod_zero"}, @{thm "div_0"}, @{thm "mod_0"}, + @{thm "zdiv_1"}, @{thm "zmod_1"}, @{thm "div_1"}, @{thm "mod_1"}, + Suc_plus1] + addsimps @{thms add_ac} + addsimprocs [cancel_div_mod_proc] + val simpset0 = HOL_basic_ss + addsimps [mod_div_equality', Suc_plus1] + addsimps comp_arith + addsplits [split_zdiv, split_zmod, split_div', @{thm "split_min"}, @{thm "split_max"}] + (* Simp rules for changing (n::int) to int n *) + val simpset1 = HOL_basic_ss + addsimps [nat_number_of_def, zdvd_int] @ map (fn r => r RS sym) + [@{thm int_int_eq}, @{thm zle_int}, @{thm zless_int}, @{thm zadd_int}, @{thm zmult_int}] + addsplits [zdiff_int_split] + (*simp rules for elimination of int n*) + + val simpset2 = HOL_basic_ss + addsimps [@{thm nat_0_le}, @{thm all_nat}, @{thm ex_nat}, @{thm number_of1}, @{thm number_of2}, @{thm int_0}, @{thm int_1}] + addcongs [@{thm conj_le_cong}, @{thm imp_le_cong}] + (* simp rules for elimination of abs *) + val simpset3 = HOL_basic_ss addsplits [@{thm abs_split}] + val ct = cterm_of thy (HOLogic.mk_Trueprop t) + (* Theorem for the nat --> int transformation *) + val pre_thm = Seq.hd (EVERY + [simp_tac mod_div_simpset 1, simp_tac simpset0 1, + TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), + TRY (simp_tac simpset3 1), TRY (simp_tac cooper_ss 1)] + (trivial ct)) + fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) + (* The result of the quantifier elimination *) + val (th, tac) = case (prop_of pre_thm) of + Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ => + let val pth = linzqe_oracle (cterm_of thy (Pattern.eta_long [] t1)) + in + ((pth RS iffD2) RS pre_thm, + assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)) + end + | _ => (pre_thm, assm_tac i) + in (rtac (((mp_step nh) o (spec_step np)) th) i + THEN tac) st + end handle Subscript => no_tac st); + +fun linz_args meth = + let val parse_flag = + Args.$$$ "no_quantify" >> (K (K false)); + in + Method.simple_args + (Scan.optional (Args.$$$ "(" |-- Scan.repeat1 parse_flag --| Args.$$$ ")") [] >> + curry (Library.foldl op |>) true) + (fn q => fn ctxt => meth ctxt q 1) + end; + +fun linz_method ctxt q i = Method.METHOD (fn facts => + Method.insert_tac facts 1 THEN linz_tac ctxt q i); + +val setup = + Method.add_method ("cooper", + linz_args linz_method, + "decision procedure for linear integer arithmetic"); + +end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/Reflection/ferrack_tac.ML --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Reflection/ferrack_tac.ML Tue Feb 03 16:50:41 2009 +0100 @@ -0,0 +1,113 @@ +(* Title: HOL/Reflection/ferrack_tac.ML + Author: Amine Chaieb, TU Muenchen +*) + +structure Ferrack_Tac = +struct + +val trace = ref false; +fun trace_msg s = if !trace then tracing s else (); + +val ferrack_ss = let val ths = [@{thm real_of_int_inject}, @{thm real_of_int_less_iff}, + @{thm real_of_int_le_iff}] + in @{simpset} delsimps ths addsimps (map (fn th => th RS sym) ths) + end; + +val binarith = + @{thms normalize_bin_simps} @ @{thms pred_bin_simps} @ @{thms succ_bin_simps} @ + @{thms add_bin_simps} @ @{thms minus_bin_simps} @ @{thms mult_bin_simps}; +val comp_arith = binarith @ simp_thms + +val zdvd_int = @{thm zdvd_int}; +val zdiff_int_split = @{thm zdiff_int_split}; +val all_nat = @{thm all_nat}; +val ex_nat = @{thm ex_nat}; +val number_of1 = @{thm number_of1}; +val number_of2 = @{thm number_of2}; +val split_zdiv = @{thm split_zdiv}; +val split_zmod = @{thm split_zmod}; +val mod_div_equality' = @{thm mod_div_equality'}; +val split_div' = @{thm split_div'}; +val Suc_plus1 = @{thm Suc_plus1}; +val imp_le_cong = @{thm imp_le_cong}; +val conj_le_cong = @{thm conj_le_cong}; +val nat_mod_add_eq = @{thm mod_add1_eq} RS sym; +val nat_mod_add_left_eq = @{thm mod_add_left_eq} RS sym; +val nat_mod_add_right_eq = @{thm mod_add_right_eq} RS sym; +val int_mod_add_eq = @{thm zmod_zadd1_eq} RS sym; +val int_mod_add_left_eq = @{thm zmod_zadd_left_eq} RS sym; +val int_mod_add_right_eq = @{thm zmod_zadd_right_eq} RS sym; +val nat_div_add_eq = @{thm div_add1_eq} RS sym; +val int_div_add_eq = @{thm zdiv_zadd1_eq} RS sym; +val ZDIVISION_BY_ZERO_MOD = @{thm DIVISION_BY_ZERO} RS conjunct2; +val ZDIVISION_BY_ZERO_DIV = @{thm DIVISION_BY_ZERO} RS conjunct1; + +fun prepare_for_linr sg q fm = + let + val ps = Logic.strip_params fm + val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) + val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) + fun mk_all ((s, T), (P,n)) = + if 0 mem loose_bnos P then + (HOLogic.all_const T $ Abs (s, T, P), n) + else (incr_boundvars ~1 P, n-1) + fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; + val rhs = hs +(* val (rhs,irhs) = List.partition (relevant (rev ps)) hs *) + val np = length ps + val (fm',np) = foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) + (foldr HOLogic.mk_imp c rhs, np) ps + val (vs, _) = List.partition (fn t => q orelse (type_of t) = HOLogic.natT) + (OldTerm.term_frees fm' @ OldTerm.term_vars fm'); + val fm2 = foldr mk_all2 fm' vs + in (fm2, np + length vs, length rhs) end; + +(*Object quantifier to meta --*) +fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; + +(* object implication to meta---*) +fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; + + +fun linr_tac ctxt q i = + (ObjectLogic.atomize_prems_tac i) + THEN (REPEAT_DETERM (split_tac [@{thm split_min}, @{thm split_max}, @{thm abs_split}] i)) + THEN (fn st => + let + val g = List.nth (prems_of st, i - 1) + val thy = ProofContext.theory_of ctxt + (* Transform the term*) + val (t,np,nh) = prepare_for_linr thy q g + (* Some simpsets for dealing with mod div abs and nat*) + val simpset0 = Simplifier.theory_context thy HOL_basic_ss addsimps comp_arith + val ct = cterm_of thy (HOLogic.mk_Trueprop t) + (* Theorem for the nat --> int transformation *) + val pre_thm = Seq.hd (EVERY + [simp_tac simpset0 1, + TRY (simp_tac (Simplifier.theory_context thy ferrack_ss) 1)] + (trivial ct)) + fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) + (* The result of the quantifier elimination *) + val (th, tac) = case (prop_of pre_thm) of + Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ => + let val pth = linr_oracle (cterm_of thy (Pattern.eta_long [] t1)) + in + (trace_msg ("calling procedure with term:\n" ^ + Syntax.string_of_term ctxt t1); + ((pth RS iffD2) RS pre_thm, + assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))) + end + | _ => (pre_thm, assm_tac i) + in (rtac (((mp_step nh) o (spec_step np)) th) i + THEN tac) st + end handle Subscript => no_tac st); + +fun linr_meth src = + Method.syntax (Args.mode "no_quantify") src + #> (fn (q, ctxt) => Method.SIMPLE_METHOD' (linr_tac ctxt (not q))); + +val setup = + Method.add_method ("rferrack", linr_meth, + "decision procedure for linear real arithmetic"); + +end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/Reflection/mir_tac.ML --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Reflection/mir_tac.ML Tue Feb 03 16:50:41 2009 +0100 @@ -0,0 +1,168 @@ +(* Title: HOL/Reflection/mir_tac.ML + Author: Amine Chaieb, TU Muenchen +*) + +structure Mir_Tac = +struct + +val trace = ref false; +fun trace_msg s = if !trace then tracing s else (); + +val mir_ss = +let val ths = map thm ["real_of_int_inject", "real_of_int_less_iff", "real_of_int_le_iff"] +in @{simpset} delsimps ths addsimps (map (fn th => th RS sym) ths) +end; + +val nT = HOLogic.natT; + val nat_arith = map thm ["add_nat_number_of", "diff_nat_number_of", + "mult_nat_number_of", "eq_nat_number_of", "less_nat_number_of"]; + + val comp_arith = (map thm ["Let_def", "if_False", "if_True", "add_0", + "add_Suc", "add_number_of_left", "mult_number_of_left", + "Suc_eq_add_numeral_1"])@ + (map (fn s => thm s RS sym) ["numeral_1_eq_1", "numeral_0_eq_0"]) + @ @{thms arith_simps} @ nat_arith @ @{thms rel_simps} + val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"}, + @{thm "real_of_nat_number_of"}, + @{thm "real_of_nat_Suc"}, @{thm "real_of_nat_one"}, @{thm "real_of_one"}, + @{thm "real_of_int_zero"}, @{thm "real_of_nat_zero"}, + @{thm "Ring_and_Field.divide_zero"}, + @{thm "divide_divide_eq_left"}, @{thm "times_divide_eq_right"}, + @{thm "times_divide_eq_left"}, @{thm "divide_divide_eq_right"}, + @{thm "diff_def"}, @{thm "minus_divide_left"}] +val comp_ths = ths @ comp_arith @ simp_thms + + +val zdvd_int = @{thm "zdvd_int"}; +val zdiff_int_split = @{thm "zdiff_int_split"}; +val all_nat = @{thm "all_nat"}; +val ex_nat = @{thm "ex_nat"}; +val number_of1 = @{thm "number_of1"}; +val number_of2 = @{thm "number_of2"}; +val split_zdiv = @{thm "split_zdiv"}; +val split_zmod = @{thm "split_zmod"}; +val mod_div_equality' = @{thm "mod_div_equality'"}; +val split_div' = @{thm "split_div'"}; +val Suc_plus1 = @{thm "Suc_plus1"}; +val imp_le_cong = @{thm "imp_le_cong"}; +val conj_le_cong = @{thm "conj_le_cong"}; +val nat_mod_add_eq = @{thm "mod_add1_eq"} RS sym; +val nat_mod_add_left_eq = @{thm "mod_add_left_eq"} RS sym; +val nat_mod_add_right_eq = @{thm "mod_add_right_eq"} RS sym; +val int_mod_add_eq = @{thm "zmod_zadd1_eq"} RS sym; +val int_mod_add_left_eq = @{thm "zmod_zadd_left_eq"} RS sym; +val int_mod_add_right_eq = @{thm "zmod_zadd_right_eq"} RS sym; +val nat_div_add_eq = @{thm "div_add1_eq"} RS sym; +val int_div_add_eq = @{thm "zdiv_zadd1_eq"} RS sym; +val ZDIVISION_BY_ZERO_MOD = @{thm "DIVISION_BY_ZERO"} RS conjunct2; +val ZDIVISION_BY_ZERO_DIV = @{thm "DIVISION_BY_ZERO"} RS conjunct1; + +fun prepare_for_mir thy q fm = + let + val ps = Logic.strip_params fm + val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) + val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) + fun mk_all ((s, T), (P,n)) = + if 0 mem loose_bnos P then + (HOLogic.all_const T $ Abs (s, T, P), n) + else (incr_boundvars ~1 P, n-1) + fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; + val rhs = hs +(* val (rhs,irhs) = List.partition (relevant (rev ps)) hs *) + val np = length ps + val (fm',np) = foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) + (foldr HOLogic.mk_imp c rhs, np) ps + val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT) + (OldTerm.term_frees fm' @ OldTerm.term_vars fm'); + val fm2 = foldr mk_all2 fm' vs + in (fm2, np + length vs, length rhs) end; + +(*Object quantifier to meta --*) +fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; + +(* object implication to meta---*) +fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; + + +fun mir_tac ctxt q i = + (ObjectLogic.atomize_prems_tac i) + THEN (simp_tac (HOL_basic_ss addsimps [@{thm "abs_ge_zero"}] addsimps simp_thms) i) + THEN (REPEAT_DETERM (split_tac [@{thm "split_min"}, @{thm "split_max"},@{thm "abs_split"}] i)) + THEN (fn st => + let + val g = List.nth (prems_of st, i - 1) + val thy = ProofContext.theory_of ctxt + (* Transform the term*) + val (t,np,nh) = prepare_for_mir thy q g + (* Some simpsets for dealing with mod div abs and nat*) + val mod_div_simpset = HOL_basic_ss + addsimps [refl,nat_mod_add_eq, + @{thm "mod_self"}, @{thm "zmod_self"}, + @{thm "zdiv_zero"},@{thm "zmod_zero"},@{thm "div_0"}, @{thm "mod_0"}, + @{thm "zdiv_1"}, @{thm "zmod_1"}, @{thm "div_1"}, @{thm "mod_1"}, + @{thm "Suc_plus1"}] + addsimps @{thms add_ac} + addsimprocs [cancel_div_mod_proc] + val simpset0 = HOL_basic_ss + addsimps [mod_div_equality', Suc_plus1] + addsimps comp_ths + addsplits [@{thm "split_zdiv"}, @{thm "split_zmod"}, @{thm "split_div'"}, @{thm "split_min"}, @{thm "split_max"}] + (* Simp rules for changing (n::int) to int n *) + val simpset1 = HOL_basic_ss + addsimps [@{thm "nat_number_of_def"}, @{thm "zdvd_int"}] @ map (fn r => r RS sym) + [@{thm "int_int_eq"}, @{thm "zle_int"}, @{thm "zless_int"}, @{thm "zadd_int"}, + @{thm "zmult_int"}] + addsplits [@{thm "zdiff_int_split"}] + (*simp rules for elimination of int n*) + + val simpset2 = HOL_basic_ss + addsimps [@{thm "nat_0_le"}, @{thm "all_nat"}, @{thm "ex_nat"}, @{thm "number_of1"}, + @{thm "number_of2"}, @{thm "int_0"}, @{thm "int_1"}] + addcongs [@{thm "conj_le_cong"}, @{thm "imp_le_cong"}] + (* simp rules for elimination of abs *) + val ct = cterm_of thy (HOLogic.mk_Trueprop t) + (* Theorem for the nat --> int transformation *) + val pre_thm = Seq.hd (EVERY + [simp_tac mod_div_simpset 1, simp_tac simpset0 1, + TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), TRY (simp_tac mir_ss 1)] + (trivial ct)) + fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) + (* The result of the quantifier elimination *) + val (th, tac) = case (prop_of pre_thm) of + Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ => + let val pth = + (* If quick_and_dirty then run without proof generation as oracle*) + if !quick_and_dirty + then mirfr_oracle (false, cterm_of thy (Pattern.eta_long [] t1)) + else mirfr_oracle (true, cterm_of thy (Pattern.eta_long [] t1)) + in + (trace_msg ("calling procedure with term:\n" ^ + Syntax.string_of_term ctxt t1); + ((pth RS iffD2) RS pre_thm, + assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))) + end + | _ => (pre_thm, assm_tac i) + in (rtac (((mp_step nh) o (spec_step np)) th) i + THEN tac) st + end handle Subscript => no_tac st); + +fun mir_args meth = + let val parse_flag = + Args.$$$ "no_quantify" >> (K (K false)); + in + Method.simple_args + (Scan.optional (Args.$$$ "(" |-- Scan.repeat1 parse_flag --| Args.$$$ ")") [] >> + curry (Library.foldl op |>) true) + (fn q => fn ctxt => meth ctxt q 1) + end; + +fun mir_method ctxt q i = Method.METHOD (fn facts => + Method.insert_tac facts 1 THEN mir_tac ctxt q i); + +val setup = + Method.add_method ("mir", + mir_args mir_method, + "decision procedure for MIR arithmetic"); + + +end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/MIR.thy --- a/src/HOL/ex/MIR.thy Tue Feb 03 16:50:40 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5933 +0,0 @@ -(* Title: HOL/ex/MIR.thy - Author: Amine Chaieb -*) - -theory MIR -imports Main RComplete Code_Integer Efficient_Nat -uses ("mirtac.ML") -begin - -section {* Quantifier elimination for @{text "\ (0, 1, +, floor, <)"} *} - -declare real_of_int_floor_cancel [simp del] - -primrec alluopairs:: "'a list \ ('a \ 'a) list" where - "alluopairs [] = []" -| "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)" - -lemma alluopairs_set1: "set (alluopairs xs) \ {(x,y). x\ set xs \ y\ set xs}" -by (induct xs, auto) - -lemma alluopairs_set: - "\x\ set xs ; y \ set xs\ \ (x,y) \ set (alluopairs xs) \ (y,x) \ set (alluopairs xs) " -by (induct xs, auto) - -lemma alluopairs_ex: - assumes Pc: "\ x y. P x y = P y x" - shows "(\ x \ set xs. \ y \ set xs. P x y) = (\ (x,y) \ set (alluopairs xs). P x y)" -proof - assume "\x\set xs. \y\set xs. P x y" - then obtain x y where x: "x \ set xs" and y:"y \ set xs" and P: "P x y" by blast - from alluopairs_set[OF x y] P Pc show"\(x, y)\set (alluopairs xs). P x y" - by auto -next - assume "\(x, y)\set (alluopairs xs). P x y" - then obtain "x" and "y" where xy:"(x,y) \ set (alluopairs xs)" and P: "P x y" by blast+ - from xy have "x \ set xs \ y\ set xs" using alluopairs_set1 by blast - with P show "\x\set xs. \y\set xs. P x y" by blast -qed - - (* generate a list from i to j*) -consts iupt :: "int \ int \ int list" -recdef iupt "measure (\ (i,j). nat (j-i +1))" - "iupt (i,j) = (if j (x#xs) ! n = xs ! (n - 1)" -using Nat.gr0_conv_Suc -by clarsimp - - -lemma myl: "\ (a::'a::{pordered_ab_group_add}) (b::'a). (a \ b) = (0 \ b - a)" -proof(clarify) - fix x y ::"'a" - have "(x \ y) = (x - y \ 0)" by (simp only: le_iff_diff_le_0[where a="x" and b="y"]) - also have "\ = (- (y - x) \ 0)" by simp - also have "\ = (0 \ y - x)" by (simp only: neg_le_0_iff_le[where a="y-x"]) - finally show "(x \ y) = (0 \ y - x)" . -qed - -lemma myless: "\ (a::'a::{pordered_ab_group_add}) (b::'a). (a < b) = (0 < b - a)" -proof(clarify) - fix x y ::"'a" - have "(x < y) = (x - y < 0)" by (simp only: less_iff_diff_less_0[where a="x" and b="y"]) - also have "\ = (- (y - x) < 0)" by simp - also have "\ = (0 < y - x)" by (simp only: neg_less_0_iff_less[where a="y-x"]) - finally show "(x < y) = (0 < y - x)" . -qed - -lemma myeq: "\ (a::'a::{pordered_ab_group_add}) (b::'a). (a = b) = (0 = b - a)" - by auto - - (* Maybe should be added to the library \ *) -lemma floor_int_eq: "(real n\ x \ x < real (n+1)) = (floor x = n)" -proof( auto) - assume lb: "real n \ x" - and ub: "x < real n + 1" - have "real (floor x) \ x" by simp - hence "real (floor x) < real (n + 1) " using ub by arith - hence "floor x < n+1" by simp - moreover from lb have "n \ floor x" using floor_mono2[where x="real n" and y="x"] - by simp ultimately show "floor x = n" by simp -qed - -(* Periodicity of dvd *) -lemma dvd_period: - assumes advdd: "(a::int) dvd d" - shows "(a dvd (x + t)) = (a dvd ((x+ c*d) + t))" - using advdd -proof- - {fix x k - from inf_period(3)[OF advdd, rule_format, where x=x and k="-k"] - have " ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))" by simp} - hence "\x.\k. ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))" by simp - then show ?thesis by simp -qed - - (* The Divisibility relation between reals *) -definition - rdvd:: "real \ real \ bool" (infixl "rdvd" 50) -where - rdvd_def: "x rdvd y \ (\k\int. y = x * real k)" - -lemma int_rdvd_real: - shows "real (i::int) rdvd x = (i dvd (floor x) \ real (floor x) = x)" (is "?l = ?r") -proof - assume "?l" - hence th: "\ k. x=real (i*k)" by (simp add: rdvd_def) - hence th': "real (floor x) = x" by (auto simp del: real_of_int_mult) - with th have "\ k. real (floor x) = real (i*k)" by simp - hence "\ k. floor x = i*k" by (simp only: real_of_int_inject) - thus ?r using th' by (simp add: dvd_def) -next - assume "?r" hence "(i\int) dvd \x\real\" .. - hence "\ k. real (floor x) = real (i*k)" - by (simp only: real_of_int_inject) (simp add: dvd_def) - thus ?l using prems by (simp add: rdvd_def) -qed - -lemma int_rdvd_iff: "(real (i::int) rdvd real t) = (i dvd t)" -by (auto simp add: rdvd_def dvd_def) (rule_tac x="k" in exI, simp only :real_of_int_mult[symmetric]) - - -lemma rdvd_abs1: - "(abs (real d) rdvd t) = (real (d ::int) rdvd t)" -proof - assume d: "real d rdvd t" - from d int_rdvd_real have d2: "d dvd (floor t)" and ti: "real (floor t) = t" by auto - - from iffD2[OF zdvd_abs1] d2 have "(abs d) dvd (floor t)" by blast - with ti int_rdvd_real[symmetric] have "real (abs d) rdvd t" by blast - thus "abs (real d) rdvd t" by simp -next - assume "abs (real d) rdvd t" hence "real (abs d) rdvd t" by simp - with int_rdvd_real[where i="abs d" and x="t"] have d2: "abs d dvd floor t" and ti: "real (floor t) =t" by auto - from iffD1[OF zdvd_abs1] d2 have "d dvd floor t" by blast - with ti int_rdvd_real[symmetric] show "real d rdvd t" by blast -qed - -lemma rdvd_minus: "(real (d::int) rdvd t) = (real d rdvd -t)" - apply (auto simp add: rdvd_def) - apply (rule_tac x="-k" in exI, simp) - apply (rule_tac x="-k" in exI, simp) -done - -lemma rdvd_left_0_eq: "(0 rdvd t) = (t=0)" -by (auto simp add: rdvd_def) - -lemma rdvd_mult: - assumes knz: "k\0" - shows "(real (n::int) * real (k::int) rdvd x * real k) = (real n rdvd x)" -using knz by (simp add:rdvd_def) - -lemma rdvd_trans: assumes mn:"m rdvd n" and nk:"n rdvd k" - shows "m rdvd k" -proof- - from rdvd_def mn obtain c where nmc:"n = m * real (c::int)" by auto - from rdvd_def nk obtain c' where nkc:"k = n * real (c'::int)" by auto - hence "k = m * real (c * c')" using nmc by simp - thus ?thesis using rdvd_def by blast -qed - - (*********************************************************************************) - (**** SHADOW SYNTAX AND SEMANTICS ****) - (*********************************************************************************) - -datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num - | Mul int num | Floor num| CF int num num - - (* A size for num to make inductive proofs simpler*) -primrec num_size :: "num \ nat" where - "num_size (C c) = 1" -| "num_size (Bound n) = 1" -| "num_size (Neg a) = 1 + num_size a" -| "num_size (Add a b) = 1 + num_size a + num_size b" -| "num_size (Sub a b) = 3 + num_size a + num_size b" -| "num_size (CN n c a) = 4 + num_size a " -| "num_size (CF c a b) = 4 + num_size a + num_size b" -| "num_size (Mul c a) = 1 + num_size a" -| "num_size (Floor a) = 1 + num_size a" - - (* Semantics of numeral terms (num) *) -primrec Inum :: "real list \ num \ real" where - "Inum bs (C c) = (real c)" -| "Inum bs (Bound n) = bs!n" -| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)" -| "Inum bs (Neg a) = -(Inum bs a)" -| "Inum bs (Add a b) = Inum bs a + Inum bs b" -| "Inum bs (Sub a b) = Inum bs a - Inum bs b" -| "Inum bs (Mul c a) = (real c) * Inum bs a" -| "Inum bs (Floor a) = real (floor (Inum bs a))" -| "Inum bs (CF c a b) = real c * real (floor (Inum bs a)) + Inum bs b" -definition "isint t bs \ real (floor (Inum bs t)) = Inum bs t" - -lemma isint_iff: "isint n bs = (real (floor (Inum bs n)) = Inum bs n)" -by (simp add: isint_def) - -lemma isint_Floor: "isint (Floor n) bs" - by (simp add: isint_iff) - -lemma isint_Mul: "isint e bs \ isint (Mul c e) bs" -proof- - let ?e = "Inum bs e" - let ?fe = "floor ?e" - assume be: "isint e bs" hence efe:"real ?fe = ?e" by (simp add: isint_iff) - have "real ((floor (Inum bs (Mul c e)))) = real (floor (real (c * ?fe)))" using efe by simp - also have "\ = real (c* ?fe)" by (simp only: floor_real_of_int) - also have "\ = real c * ?e" using efe by simp - finally show ?thesis using isint_iff by simp -qed - -lemma isint_neg: "isint e bs \ isint (Neg e) bs" -proof- - let ?I = "\ t. Inum bs t" - assume ie: "isint e bs" - hence th: "real (floor (?I e)) = ?I e" by (simp add: isint_def) - have "real (floor (?I (Neg e))) = real (floor (- (real (floor (?I e)))))" by (simp add: th) - also have "\ = - real (floor (?I e))" by(simp add: floor_minus_real_of_int) - finally show "isint (Neg e) bs" by (simp add: isint_def th) -qed - -lemma isint_sub: - assumes ie: "isint e bs" shows "isint (Sub (C c) e) bs" -proof- - let ?I = "\ t. Inum bs t" - from ie have th: "real (floor (?I e)) = ?I e" by (simp add: isint_def) - have "real (floor (?I (Sub (C c) e))) = real (floor ((real (c -floor (?I e)))))" by (simp add: th) - also have "\ = real (c- floor (?I e))" by(simp add: floor_minus_real_of_int) - finally show "isint (Sub (C c) e) bs" by (simp add: isint_def th) -qed - -lemma isint_add: assumes - ai:"isint a bs" and bi: "isint b bs" shows "isint (Add a b) bs" -proof- - let ?a = "Inum bs a" - let ?b = "Inum bs b" - from ai bi isint_iff have "real (floor (?a + ?b)) = real (floor (real (floor ?a) + real (floor ?b)))" by simp - also have "\ = real (floor ?a) + real (floor ?b)" by simp - also have "\ = ?a + ?b" using ai bi isint_iff by simp - finally show "isint (Add a b) bs" by (simp add: isint_iff) -qed - -lemma isint_c: "isint (C j) bs" - by (simp add: isint_iff) - - - (* FORMULAE *) -datatype fm = - T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num| - NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm - - - (* A size for fm *) -fun fmsize :: "fm \ nat" where - "fmsize (NOT p) = 1 + fmsize p" -| "fmsize (And p q) = 1 + fmsize p + fmsize q" -| "fmsize (Or p q) = 1 + fmsize p + fmsize q" -| "fmsize (Imp p q) = 3 + fmsize p + fmsize q" -| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" -| "fmsize (E p) = 1 + fmsize p" -| "fmsize (A p) = 4+ fmsize p" -| "fmsize (Dvd i t) = 2" -| "fmsize (NDvd i t) = 2" -| "fmsize p = 1" - (* several lemmas about fmsize *) -lemma fmsize_pos: "fmsize p > 0" -by (induct p rule: fmsize.induct) simp_all - - (* Semantics of formulae (fm) *) -primrec Ifm ::"real list \ fm \ bool" where - "Ifm bs T = True" -| "Ifm bs F = False" -| "Ifm bs (Lt a) = (Inum bs a < 0)" -| "Ifm bs (Gt a) = (Inum bs a > 0)" -| "Ifm bs (Le a) = (Inum bs a \ 0)" -| "Ifm bs (Ge a) = (Inum bs a \ 0)" -| "Ifm bs (Eq a) = (Inum bs a = 0)" -| "Ifm bs (NEq a) = (Inum bs a \ 0)" -| "Ifm bs (Dvd i b) = (real i rdvd Inum bs b)" -| "Ifm bs (NDvd i b) = (\(real i rdvd Inum bs b))" -| "Ifm bs (NOT p) = (\ (Ifm bs p))" -| "Ifm bs (And p q) = (Ifm bs p \ Ifm bs q)" -| "Ifm bs (Or p q) = (Ifm bs p \ Ifm bs q)" -| "Ifm bs (Imp p q) = ((Ifm bs p) \ (Ifm bs q))" -| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)" -| "Ifm bs (E p) = (\ x. Ifm (x#bs) p)" -| "Ifm bs (A p) = (\ x. Ifm (x#bs) p)" - -consts prep :: "fm \ fm" -recdef prep "measure fmsize" - "prep (E T) = T" - "prep (E F) = F" - "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))" - "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))" - "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" - "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))" - "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" - "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" - "prep (E p) = E (prep p)" - "prep (A (And p q)) = And (prep (A p)) (prep (A q))" - "prep (A p) = prep (NOT (E (NOT p)))" - "prep (NOT (NOT p)) = prep p" - "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))" - "prep (NOT (A p)) = prep (E (NOT p))" - "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))" - "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))" - "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))" - "prep (NOT p) = NOT (prep p)" - "prep (Or p q) = Or (prep p) (prep q)" - "prep (And p q) = And (prep p) (prep q)" - "prep (Imp p q) = prep (Or (NOT p) q)" - "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))" - "prep p = p" -(hints simp add: fmsize_pos) -lemma prep: "\ bs. Ifm bs (prep p) = Ifm bs p" -by (induct p rule: prep.induct, auto) - - - (* Quantifier freeness *) -fun qfree:: "fm \ bool" where - "qfree (E p) = False" - | "qfree (A p) = False" - | "qfree (NOT p) = qfree p" - | "qfree (And p q) = (qfree p \ qfree q)" - | "qfree (Or p q) = (qfree p \ qfree q)" - | "qfree (Imp p q) = (qfree p \ qfree q)" - | "qfree (Iff p q) = (qfree p \ qfree q)" - | "qfree p = True" - - (* Boundedness and substitution *) -primrec numbound0 :: "num \ bool" (* a num is INDEPENDENT of Bound 0 *) where - "numbound0 (C c) = True" - | "numbound0 (Bound n) = (n>0)" - | "numbound0 (CN n i a) = (n > 0 \ numbound0 a)" - | "numbound0 (Neg a) = numbound0 a" - | "numbound0 (Add a b) = (numbound0 a \ numbound0 b)" - | "numbound0 (Sub a b) = (numbound0 a \ numbound0 b)" - | "numbound0 (Mul i a) = numbound0 a" - | "numbound0 (Floor a) = numbound0 a" - | "numbound0 (CF c a b) = (numbound0 a \ numbound0 b)" - -lemma numbound0_I: - assumes nb: "numbound0 a" - shows "Inum (b#bs) a = Inum (b'#bs) a" - using nb by (induct a) (auto simp add: nth_pos2) - -lemma numbound0_gen: - assumes nb: "numbound0 t" and ti: "isint t (x#bs)" - shows "\ y. isint t (y#bs)" -using nb ti -proof(clarify) - fix y - from numbound0_I[OF nb, where bs="bs" and b="y" and b'="x"] ti[simplified isint_def] - show "isint t (y#bs)" - by (simp add: isint_def) -qed - -primrec bound0:: "fm \ bool" (* A Formula is independent of Bound 0 *) where - "bound0 T = True" - | "bound0 F = True" - | "bound0 (Lt a) = numbound0 a" - | "bound0 (Le a) = numbound0 a" - | "bound0 (Gt a) = numbound0 a" - | "bound0 (Ge a) = numbound0 a" - | "bound0 (Eq a) = numbound0 a" - | "bound0 (NEq a) = numbound0 a" - | "bound0 (Dvd i a) = numbound0 a" - | "bound0 (NDvd i a) = numbound0 a" - | "bound0 (NOT p) = bound0 p" - | "bound0 (And p q) = (bound0 p \ bound0 q)" - | "bound0 (Or p q) = (bound0 p \ bound0 q)" - | "bound0 (Imp p q) = ((bound0 p) \ (bound0 q))" - | "bound0 (Iff p q) = (bound0 p \ bound0 q)" - | "bound0 (E p) = False" - | "bound0 (A p) = False" - -lemma bound0_I: - assumes bp: "bound0 p" - shows "Ifm (b#bs) p = Ifm (b'#bs) p" - using bp numbound0_I [where b="b" and bs="bs" and b'="b'"] - by (induct p) (auto simp add: nth_pos2) - -primrec numsubst0:: "num \ num \ num" (* substitute a num into a num for Bound 0 *) where - "numsubst0 t (C c) = (C c)" - | "numsubst0 t (Bound n) = (if n=0 then t else Bound n)" - | "numsubst0 t (CN n i a) = (if n=0 then Add (Mul i t) (numsubst0 t a) else CN n i (numsubst0 t a))" - | "numsubst0 t (CF i a b) = CF i (numsubst0 t a) (numsubst0 t b)" - | "numsubst0 t (Neg a) = Neg (numsubst0 t a)" - | "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)" - | "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)" - | "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)" - | "numsubst0 t (Floor a) = Floor (numsubst0 t a)" - -lemma numsubst0_I: - shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t" - by (induct t) (simp_all add: nth_pos2) - -lemma numsubst0_I': - assumes nb: "numbound0 a" - shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t" - by (induct t) (simp_all add: nth_pos2 numbound0_I[OF nb, where b="b" and b'="b'"]) - -primrec subst0:: "num \ fm \ fm" (* substitue a num into a formula for Bound 0 *) where - "subst0 t T = T" - | "subst0 t F = F" - | "subst0 t (Lt a) = Lt (numsubst0 t a)" - | "subst0 t (Le a) = Le (numsubst0 t a)" - | "subst0 t (Gt a) = Gt (numsubst0 t a)" - | "subst0 t (Ge a) = Ge (numsubst0 t a)" - | "subst0 t (Eq a) = Eq (numsubst0 t a)" - | "subst0 t (NEq a) = NEq (numsubst0 t a)" - | "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)" - | "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)" - | "subst0 t (NOT p) = NOT (subst0 t p)" - | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)" - | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)" - | "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)" - | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)" - -lemma subst0_I: assumes qfp: "qfree p" - shows "Ifm (b#bs) (subst0 a p) = Ifm ((Inum (b#bs) a)#bs) p" - using qfp numsubst0_I[where b="b" and bs="bs" and a="a"] - by (induct p) (simp_all add: nth_pos2 ) - -consts - decrnum:: "num \ num" - decr :: "fm \ fm" - -recdef decrnum "measure size" - "decrnum (Bound n) = Bound (n - 1)" - "decrnum (Neg a) = Neg (decrnum a)" - "decrnum (Add a b) = Add (decrnum a) (decrnum b)" - "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" - "decrnum (Mul c a) = Mul c (decrnum a)" - "decrnum (Floor a) = Floor (decrnum a)" - "decrnum (CN n c a) = CN (n - 1) c (decrnum a)" - "decrnum (CF c a b) = CF c (decrnum a) (decrnum b)" - "decrnum a = a" - -recdef decr "measure size" - "decr (Lt a) = Lt (decrnum a)" - "decr (Le a) = Le (decrnum a)" - "decr (Gt a) = Gt (decrnum a)" - "decr (Ge a) = Ge (decrnum a)" - "decr (Eq a) = Eq (decrnum a)" - "decr (NEq a) = NEq (decrnum a)" - "decr (Dvd i a) = Dvd i (decrnum a)" - "decr (NDvd i a) = NDvd i (decrnum a)" - "decr (NOT p) = NOT (decr p)" - "decr (And p q) = And (decr p) (decr q)" - "decr (Or p q) = Or (decr p) (decr q)" - "decr (Imp p q) = Imp (decr p) (decr q)" - "decr (Iff p q) = Iff (decr p) (decr q)" - "decr p = p" - -lemma decrnum: assumes nb: "numbound0 t" - shows "Inum (x#bs) t = Inum bs (decrnum t)" - using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2) - -lemma decr: assumes nb: "bound0 p" - shows "Ifm (x#bs) p = Ifm bs (decr p)" - using nb - by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum) - -lemma decr_qf: "bound0 p \ qfree (decr p)" -by (induct p, simp_all) - -consts - isatom :: "fm \ bool" (* test for atomicity *) -recdef isatom "measure size" - "isatom T = True" - "isatom F = True" - "isatom (Lt a) = True" - "isatom (Le a) = True" - "isatom (Gt a) = True" - "isatom (Ge a) = True" - "isatom (Eq a) = True" - "isatom (NEq a) = True" - "isatom (Dvd i b) = True" - "isatom (NDvd i b) = True" - "isatom p = False" - -lemma numsubst0_numbound0: assumes nb: "numbound0 t" - shows "numbound0 (numsubst0 t a)" -using nb by (induct a, auto) - -lemma subst0_bound0: assumes qf: "qfree p" and nb: "numbound0 t" - shows "bound0 (subst0 t p)" -using qf numsubst0_numbound0[OF nb] by (induct p, auto) - -lemma bound0_qf: "bound0 p \ qfree p" -by (induct p, simp_all) - - -definition djf:: "('a \ fm) \ 'a \ fm \ fm" where - "djf f p q = (if q=T then T else if q=F then f p else - (let fp = f p in case fp of T \ T | F \ q | _ \ Or fp q))" - -definition evaldjf:: "('a \ fm) \ 'a list \ fm" where - "evaldjf f ps = foldr (djf f) ps F" - -lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)" -by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) -(cases "f p", simp_all add: Let_def djf_def) - -lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\ p \ set ps. Ifm bs (f p))" - by(induct ps, simp_all add: evaldjf_def djf_Or) - -lemma evaldjf_bound0: - assumes nb: "\ x\ set xs. bound0 (f x)" - shows "bound0 (evaldjf f xs)" - using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) - -lemma evaldjf_qf: - assumes nb: "\ x\ set xs. qfree (f x)" - shows "qfree (evaldjf f xs)" - using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) - -consts - disjuncts :: "fm \ fm list" - conjuncts :: "fm \ fm list" -recdef disjuncts "measure size" - "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)" - "disjuncts F = []" - "disjuncts p = [p]" - -recdef conjuncts "measure size" - "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)" - "conjuncts T = []" - "conjuncts p = [p]" -lemma disjuncts: "(\ q\ set (disjuncts p). Ifm bs q) = Ifm bs p" -by(induct p rule: disjuncts.induct, auto) -lemma conjuncts: "(\ q\ set (conjuncts p). Ifm bs q) = Ifm bs p" -by(induct p rule: conjuncts.induct, auto) - -lemma disjuncts_nb: "bound0 p \ \ q\ set (disjuncts p). bound0 q" -proof- - assume nb: "bound0 p" - hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto) - thus ?thesis by (simp only: list_all_iff) -qed -lemma conjuncts_nb: "bound0 p \ \ q\ set (conjuncts p). bound0 q" -proof- - assume nb: "bound0 p" - hence "list_all bound0 (conjuncts p)" by (induct p rule:conjuncts.induct,auto) - thus ?thesis by (simp only: list_all_iff) -qed - -lemma disjuncts_qf: "qfree p \ \ q\ set (disjuncts p). qfree q" -proof- - assume qf: "qfree p" - hence "list_all qfree (disjuncts p)" - by (induct p rule: disjuncts.induct, auto) - thus ?thesis by (simp only: list_all_iff) -qed -lemma conjuncts_qf: "qfree p \ \ q\ set (conjuncts p). qfree q" -proof- - assume qf: "qfree p" - hence "list_all qfree (conjuncts p)" - by (induct p rule: conjuncts.induct, auto) - thus ?thesis by (simp only: list_all_iff) -qed - -constdefs DJ :: "(fm \ fm) \ fm \ fm" - "DJ f p \ evaldjf f (disjuncts p)" - -lemma DJ: assumes fdj: "\ p q. f (Or p q) = Or (f p) (f q)" - and fF: "f F = F" - shows "Ifm bs (DJ f p) = Ifm bs (f p)" -proof- - have "Ifm bs (DJ f p) = (\ q \ set (disjuncts p). Ifm bs (f q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto) - finally show ?thesis . -qed - -lemma DJ_qf: assumes - fqf: "\ p. qfree p \ qfree (f p)" - shows "\p. qfree p \ qfree (DJ f p) " -proof(clarify) - fix p assume qf: "qfree p" - have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def) - from disjuncts_qf[OF qf] have "\ q\ set (disjuncts p). qfree q" . - with fqf have th':"\ q\ set (disjuncts p). qfree (f q)" by blast - - from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp -qed - -lemma DJ_qe: assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" - shows "\ bs p. qfree p \ qfree (DJ qe p) \ (Ifm bs ((DJ qe p)) = Ifm bs (E p))" -proof(clarify) - fix p::fm and bs - assume qf: "qfree p" - from qe have qth: "\ p. qfree p \ qfree (qe p)" by blast - from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto - have "Ifm bs (DJ qe p) = (\ q\ set (disjuncts p). Ifm bs (qe q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = (\ q \ set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto - also have "\ = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto) - finally show "qfree (DJ qe p) \ Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast -qed - (* Simplification *) - - (* Algebraic simplifications for nums *) -consts bnds:: "num \ nat list" - lex_ns:: "nat list \ nat list \ bool" -recdef bnds "measure size" - "bnds (Bound n) = [n]" - "bnds (CN n c a) = n#(bnds a)" - "bnds (Neg a) = bnds a" - "bnds (Add a b) = (bnds a)@(bnds b)" - "bnds (Sub a b) = (bnds a)@(bnds b)" - "bnds (Mul i a) = bnds a" - "bnds (Floor a) = bnds a" - "bnds (CF c a b) = (bnds a)@(bnds b)" - "bnds a = []" -recdef lex_ns "measure (\ (xs,ys). length xs + length ys)" - "lex_ns ([], ms) = True" - "lex_ns (ns, []) = False" - "lex_ns (n#ns, m#ms) = (n ((n = m) \ lex_ns (ns,ms))) " -constdefs lex_bnd :: "num \ num \ bool" - "lex_bnd t s \ lex_ns (bnds t, bnds s)" - -consts - numgcdh:: "num \ int \ int" - reducecoeffh:: "num \ int \ num" - dvdnumcoeff:: "num \ int \ bool" -consts maxcoeff:: "num \ int" -recdef maxcoeff "measure size" - "maxcoeff (C i) = abs i" - "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)" - "maxcoeff (CF c t s) = max (abs c) (maxcoeff s)" - "maxcoeff t = 1" - -lemma maxcoeff_pos: "maxcoeff t \ 0" - apply (induct t rule: maxcoeff.induct, auto) - done - -recdef numgcdh "measure size" - "numgcdh (C i) = (\g. zgcd i g)" - "numgcdh (CN n c t) = (\g. zgcd c (numgcdh t g))" - "numgcdh (CF c s t) = (\g. zgcd c (numgcdh t g))" - "numgcdh t = (\g. 1)" - -definition - numgcd :: "num \ int" -where - numgcd_def: "numgcd t = numgcdh t (maxcoeff t)" - -recdef reducecoeffh "measure size" - "reducecoeffh (C i) = (\ g. C (i div g))" - "reducecoeffh (CN n c t) = (\ g. CN n (c div g) (reducecoeffh t g))" - "reducecoeffh (CF c s t) = (\ g. CF (c div g) s (reducecoeffh t g))" - "reducecoeffh t = (\g. t)" - -definition - reducecoeff :: "num \ num" -where - reducecoeff_def: "reducecoeff t = - (let g = numgcd t in - if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)" - -recdef dvdnumcoeff "measure size" - "dvdnumcoeff (C i) = (\ g. g dvd i)" - "dvdnumcoeff (CN n c t) = (\ g. g dvd c \ (dvdnumcoeff t g))" - "dvdnumcoeff (CF c s t) = (\ g. g dvd c \ (dvdnumcoeff t g))" - "dvdnumcoeff t = (\g. False)" - -lemma dvdnumcoeff_trans: - assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'" - shows "dvdnumcoeff t g" - using dgt' gdg - by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg zdvd_trans[OF gdg]) - -declare zdvd_trans [trans add] - -lemma natabs0: "(nat (abs x) = 0) = (x = 0)" -by arith - -lemma numgcd0: - assumes g0: "numgcd t = 0" - shows "Inum bs t = 0" -proof- - have "\x. numgcdh t x= 0 \ Inum bs t = 0" - by (induct t rule: numgcdh.induct, auto simp add: zgcd_def gcd_zero natabs0 max_def maxcoeff_pos) - thus ?thesis using g0[simplified numgcd_def] by blast -qed - -lemma numgcdh_pos: assumes gp: "g \ 0" shows "numgcdh t g \ 0" - using gp - by (induct t rule: numgcdh.induct, auto simp add: zgcd_def) - -lemma numgcd_pos: "numgcd t \0" - by (simp add: numgcd_def numgcdh_pos maxcoeff_pos) - -lemma reducecoeffh: - assumes gt: "dvdnumcoeff t g" and gp: "g > 0" - shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t" - using gt -proof(induct t rule: reducecoeffh.induct) - case (1 i) hence gd: "g dvd i" by simp - from gp have gnz: "g \ 0" by simp - from prems show ?case by (simp add: real_of_int_div[OF gnz gd]) -next - case (2 n c t) hence gd: "g dvd c" by simp - from gp have gnz: "g \ 0" by simp - from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps) -next - case (3 c s t) hence gd: "g dvd c" by simp - from gp have gnz: "g \ 0" by simp - from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps) -qed (auto simp add: numgcd_def gp) -consts ismaxcoeff:: "num \ int \ bool" -recdef ismaxcoeff "measure size" - "ismaxcoeff (C i) = (\ x. abs i \ x)" - "ismaxcoeff (CN n c t) = (\x. abs c \ x \ (ismaxcoeff t x))" - "ismaxcoeff (CF c s t) = (\x. abs c \ x \ (ismaxcoeff t x))" - "ismaxcoeff t = (\x. True)" - -lemma ismaxcoeff_mono: "ismaxcoeff t c \ c \ c' \ ismaxcoeff t c'" -by (induct t rule: ismaxcoeff.induct, auto) - -lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" -proof (induct t rule: maxcoeff.induct) - case (2 n c t) - hence H:"ismaxcoeff t (maxcoeff t)" . - have thh: "maxcoeff t \ max (abs c) (maxcoeff t)" by (simp add: le_maxI2) - from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1) -next - case (3 c t s) - hence H1:"ismaxcoeff s (maxcoeff s)" by auto - have thh1: "maxcoeff s \ max \c\ (maxcoeff s)" by (simp add: max_def) - from ismaxcoeff_mono[OF H1 thh1] show ?case by (simp add: le_maxI1) -qed simp_all - -lemma zgcd_gt1: "zgcd i j > 1 \ ((abs i > 1 \ abs j > 1) \ (abs i = 0 \ abs j > 1) \ (abs i > 1 \ abs j = 0))" - apply (unfold zgcd_def) - apply (cases "i = 0", simp_all) - apply (cases "j = 0", simp_all) - apply (cases "abs i = 1", simp_all) - apply (cases "abs j = 1", simp_all) - apply auto - done -lemma numgcdh0:"numgcdh t m = 0 \ m =0" - by (induct t rule: numgcdh.induct, auto simp add:zgcd0) - -lemma dvdnumcoeff_aux: - assumes "ismaxcoeff t m" and mp:"m \ 0" and "numgcdh t m > 1" - shows "dvdnumcoeff t (numgcdh t m)" -using prems -proof(induct t rule: numgcdh.induct) - case (2 n c t) - let ?g = "numgcdh t m" - from prems have th:"zgcd c ?g > 1" by simp - from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] - have "(abs c > 1 \ ?g > 1) \ (abs c = 0 \ ?g > 1) \ (abs c > 1 \ ?g = 0)" by simp - moreover {assume "abs c > 1" and gp: "?g > 1" with prems - have th: "dvdnumcoeff t ?g" by simp - have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) - from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)} - moreover {assume "abs c = 0 \ ?g > 1" - with prems have th: "dvdnumcoeff t ?g" by simp - have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) - from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1) - hence ?case by simp } - moreover {assume "abs c > 1" and g0:"?g = 0" - from numgcdh0[OF g0] have "m=0". with prems have ?case by simp } - ultimately show ?case by blast -next - case (3 c s t) - let ?g = "numgcdh t m" - from prems have th:"zgcd c ?g > 1" by simp - from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] - have "(abs c > 1 \ ?g > 1) \ (abs c = 0 \ ?g > 1) \ (abs c > 1 \ ?g = 0)" by simp - moreover {assume "abs c > 1" and gp: "?g > 1" with prems - have th: "dvdnumcoeff t ?g" by simp - have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) - from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)} - moreover {assume "abs c = 0 \ ?g > 1" - with prems have th: "dvdnumcoeff t ?g" by simp - have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) - from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1) - hence ?case by simp } - moreover {assume "abs c > 1" and g0:"?g = 0" - from numgcdh0[OF g0] have "m=0". with prems have ?case by simp } - ultimately show ?case by blast -qed(auto simp add: zgcd_zdvd1) - -lemma dvdnumcoeff_aux2: - assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \ numgcd t > 0" - using prems -proof (simp add: numgcd_def) - let ?mc = "maxcoeff t" - let ?g = "numgcdh t ?mc" - have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff) - have th2: "?mc \ 0" by (rule maxcoeff_pos) - assume H: "numgcdh t ?mc > 1" - from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" . -qed - -lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t" -proof- - let ?g = "numgcd t" - have "?g \ 0" by (simp add: numgcd_pos) - hence "?g = 0 \ ?g = 1 \ ?g > 1" by auto - moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} - moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} - moreover { assume g1:"?g > 1" - from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+ - from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis - by (simp add: reducecoeff_def Let_def)} - ultimately show ?thesis by blast -qed - -lemma reducecoeffh_numbound0: "numbound0 t \ numbound0 (reducecoeffh t g)" -by (induct t rule: reducecoeffh.induct, auto) - -lemma reducecoeff_numbound0: "numbound0 t \ numbound0 (reducecoeff t)" -using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def) - -consts - simpnum:: "num \ num" - numadd:: "num \ num \ num" - nummul:: "num \ int \ num" - -recdef numadd "measure (\ (t,s). size t + size s)" - "numadd (CN n1 c1 r1,CN n2 c2 r2) = - (if n1=n2 then - (let c = c1 + c2 - in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2)))) - else if n1 \ n2 then CN n1 c1 (numadd (r1,CN n2 c2 r2)) - else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))" - "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))" - "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" - "numadd (CF c1 t1 r1,CF c2 t2 r2) = - (if t1 = t2 then - (let c=c1+c2; s= numadd(r1,r2) in (if c=0 then s else CF c t1 s)) - else if lex_bnd t1 t2 then CF c1 t1 (numadd(r1,CF c2 t2 r2)) - else CF c2 t2 (numadd(CF c1 t1 r1,r2)))" - "numadd (CF c1 t1 r1,C c) = CF c1 t1 (numadd (r1, C c))" - "numadd (C c,CF c1 t1 r1) = CF c1 t1 (numadd (r1, C c))" - "numadd (C b1, C b2) = C (b1+b2)" - "numadd (a,b) = Add a b" - -lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" -apply (induct t s rule: numadd.induct, simp_all add: Let_def) - apply (case_tac "c1+c2 = 0",case_tac "n1 \ n2", simp_all) - apply (case_tac "n1 = n2", simp_all add: algebra_simps) - apply (simp only: left_distrib[symmetric]) - apply simp -apply (case_tac "lex_bnd t1 t2", simp_all) - apply (case_tac "c1+c2 = 0") - by (case_tac "t1 = t2", simp_all add: algebra_simps left_distrib[symmetric] real_of_int_mult[symmetric] real_of_int_add[symmetric]del: real_of_int_mult real_of_int_add left_distrib) - -lemma numadd_nb[simp]: "\ numbound0 t ; numbound0 s\ \ numbound0 (numadd (t,s))" -by (induct t s rule: numadd.induct, auto simp add: Let_def) - -recdef nummul "measure size" - "nummul (C j) = (\ i. C (i*j))" - "nummul (CN n c t) = (\ i. CN n (c*i) (nummul t i))" - "nummul (CF c t s) = (\ i. CF (c*i) t (nummul s i))" - "nummul (Mul c t) = (\ i. nummul t (i*c))" - "nummul t = (\ i. Mul i t)" - -lemma nummul[simp]: "\ i. Inum bs (nummul t i) = Inum bs (Mul i t)" -by (induct t rule: nummul.induct, auto simp add: algebra_simps) - -lemma nummul_nb[simp]: "\ i. numbound0 t \ numbound0 (nummul t i)" -by (induct t rule: nummul.induct, auto) - -constdefs numneg :: "num \ num" - "numneg t \ nummul t (- 1)" - -constdefs numsub :: "num \ num \ num" - "numsub s t \ (if s = t then C 0 else numadd (s,numneg t))" - -lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)" -using numneg_def nummul by simp - -lemma numneg_nb[simp]: "numbound0 t \ numbound0 (numneg t)" -using numneg_def by simp - -lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)" -using numsub_def by simp - -lemma numsub_nb[simp]: "\ numbound0 t ; numbound0 s\ \ numbound0 (numsub t s)" -using numsub_def by simp - -lemma isint_CF: assumes si: "isint s bs" shows "isint (CF c t s) bs" -proof- - have cti: "isint (Mul c (Floor t)) bs" by (simp add: isint_Mul isint_Floor) - - have "?thesis = isint (Add (Mul c (Floor t)) s) bs" by (simp add: isint_def) - also have "\" by (simp add: isint_add cti si) - finally show ?thesis . -qed - -consts split_int:: "num \ num\num" -recdef split_int "measure num_size" - "split_int (C c) = (C 0, C c)" - "split_int (CN n c b) = - (let (bv,bi) = split_int b - in (CN n c bv, bi))" - "split_int (CF c a b) = - (let (bv,bi) = split_int b - in (bv, CF c a bi))" - "split_int a = (a,C 0)" - -lemma split_int:"\ tv ti. split_int t = (tv,ti) \ (Inum bs (Add tv ti) = Inum bs t) \ isint ti bs" -proof (induct t rule: split_int.induct) - case (2 c n b tv ti) - let ?bv = "fst (split_int b)" - let ?bi = "snd (split_int b)" - have "split_int b = (?bv,?bi)" by simp - with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+ - from prems(2) have tibi: "ti = ?bi" by (simp add: Let_def split_def) - from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def) -next - case (3 c a b tv ti) - let ?bv = "fst (split_int b)" - let ?bi = "snd (split_int b)" - have "split_int b = (?bv,?bi)" by simp - with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+ - from prems(2) have tibi: "ti = CF c a ?bi" by (simp add: Let_def split_def) - from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def isint_Floor isint_add isint_Mul isint_CF) -qed (auto simp add: Let_def isint_iff isint_Floor isint_add isint_Mul split_def algebra_simps) - -lemma split_int_nb: "numbound0 t \ numbound0 (fst (split_int t)) \ numbound0 (snd (split_int t)) " -by (induct t rule: split_int.induct, auto simp add: Let_def split_def) - -definition - numfloor:: "num \ num" -where - numfloor_def: "numfloor t = (let (tv,ti) = split_int t in - (case tv of C i \ numadd (tv,ti) - | _ \ numadd(CF 1 tv (C 0),ti)))" - -lemma numfloor[simp]: "Inum bs (numfloor t) = Inum bs (Floor t)" (is "?n t = ?N (Floor t)") -proof- - let ?tv = "fst (split_int t)" - let ?ti = "snd (split_int t)" - have tvti:"split_int t = (?tv,?ti)" by simp - {assume H: "\ v. ?tv \ C v" - hence th1: "?n t = ?N (Add (Floor ?tv) ?ti)" - by (cases ?tv, auto simp add: numfloor_def Let_def split_def numadd) - from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+ - hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp - also have "\ = real (floor (?N ?tv) + (floor (?N ?ti)))" - by (simp,subst tii[simplified isint_iff, symmetric]) simp - also have "\ = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff]) - finally have ?thesis using th1 by simp} - moreover {fix v assume H:"?tv = C v" - from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+ - hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp - also have "\ = real (floor (?N ?tv) + (floor (?N ?ti)))" - by (simp,subst tii[simplified isint_iff, symmetric]) simp - also have "\ = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff]) - finally have ?thesis by (simp add: H numfloor_def Let_def split_def numadd) } - ultimately show ?thesis by auto -qed - -lemma numfloor_nb[simp]: "numbound0 t \ numbound0 (numfloor t)" - using split_int_nb[where t="t"] - by (cases "fst(split_int t)" , auto simp add: numfloor_def Let_def split_def numadd_nb) - -recdef simpnum "measure num_size" - "simpnum (C j) = C j" - "simpnum (Bound n) = CN n 1 (C 0)" - "simpnum (Neg t) = numneg (simpnum t)" - "simpnum (Add t s) = numadd (simpnum t,simpnum s)" - "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" - "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)" - "simpnum (Floor t) = numfloor (simpnum t)" - "simpnum (CN n c t) = (if c=0 then simpnum t else CN n c (simpnum t))" - "simpnum (CF c t s) = simpnum(Add (Mul c (Floor t)) s)" - -lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t" -by (induct t rule: simpnum.induct, auto) - -lemma simpnum_numbound0[simp]: - "numbound0 t \ numbound0 (simpnum t)" -by (induct t rule: simpnum.induct, auto) - -consts nozerocoeff:: "num \ bool" -recdef nozerocoeff "measure size" - "nozerocoeff (C c) = True" - "nozerocoeff (CN n c t) = (c\0 \ nozerocoeff t)" - "nozerocoeff (CF c s t) = (c \ 0 \ nozerocoeff t)" - "nozerocoeff (Mul c t) = (c\0 \ nozerocoeff t)" - "nozerocoeff t = True" - -lemma numadd_nz : "nozerocoeff a \ nozerocoeff b \ nozerocoeff (numadd (a,b))" -by (induct a b rule: numadd.induct,auto simp add: Let_def) - -lemma nummul_nz : "\ i. i\0 \ nozerocoeff a \ nozerocoeff (nummul a i)" - by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz) - -lemma numneg_nz : "nozerocoeff a \ nozerocoeff (numneg a)" -by (simp add: numneg_def nummul_nz) - -lemma numsub_nz: "nozerocoeff a \ nozerocoeff b \ nozerocoeff (numsub a b)" -by (simp add: numsub_def numneg_nz numadd_nz) - -lemma split_int_nz: "nozerocoeff t \ nozerocoeff (fst (split_int t)) \ nozerocoeff (snd (split_int t))" -by (induct t rule: split_int.induct,auto simp add: Let_def split_def) - -lemma numfloor_nz: "nozerocoeff t \ nozerocoeff (numfloor t)" -by (simp add: numfloor_def Let_def split_def) -(cases "fst (split_int t)", simp_all add: split_int_nz numadd_nz) - -lemma simpnum_nz: "nozerocoeff (simpnum t)" -by(induct t rule: simpnum.induct, auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz numfloor_nz) - -lemma maxcoeff_nz: "nozerocoeff t \ maxcoeff t = 0 \ t = C 0" -proof (induct t rule: maxcoeff.induct) - case (2 n c t) - hence cnz: "c \0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+ - have "max (abs c) (maxcoeff t) \ abs c" by (simp add: le_maxI1) - with cnz have "max (abs c) (maxcoeff t) > 0" by arith - with prems show ?case by simp -next - case (3 c s t) - hence cnz: "c \0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+ - have "max (abs c) (maxcoeff t) \ abs c" by (simp add: le_maxI1) - with cnz have "max (abs c) (maxcoeff t) > 0" by arith - with prems show ?case by simp -qed auto - -lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0" -proof- - from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def) - from numgcdh0[OF th] have th:"maxcoeff t = 0" . - from maxcoeff_nz[OF nz th] show ?thesis . -qed - -constdefs simp_num_pair:: "(num \ int) \ num \ int" - "simp_num_pair \ (\ (t,n). (if n = 0 then (C 0, 0) else - (let t' = simpnum t ; g = numgcd t' in - if g > 1 then (let g' = zgcd n g in - if g' = 1 then (t',n) - else (reducecoeffh t' g', n div g')) - else (t',n))))" - -lemma simp_num_pair_ci: - shows "((\ (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\ (t,n). Inum bs t / real n) (t,n))" - (is "?lhs = ?rhs") -proof- - let ?t' = "simpnum t" - let ?g = "numgcd ?t'" - let ?g' = "zgcd n ?g" - {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)} - moreover - { assume nnz: "n \ 0" - {assume "\ ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def)} - moreover - {assume g1:"?g>1" hence g0: "?g > 0" by simp - from zgcd0 g1 nnz have gp0: "?g' \ 0" by simp - hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith - hence "?g'= 1 \ ?g' > 1" by arith - moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)} - moreover {assume g'1:"?g'>1" - from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" .. - let ?tt = "reducecoeffh ?t' ?g'" - let ?t = "Inum bs ?tt" - have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) - have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) - have gpdgp: "?g' dvd ?g'" by simp - from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] - have th2:"real ?g' * ?t = Inum bs ?t'" by simp - from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def) - also have "\ = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp - also have "\ = (Inum bs ?t' / real n)" - using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp - finally have "?lhs = Inum bs t / real n" by simp - then have ?thesis using prems by (simp add: simp_num_pair_def)} - ultimately have ?thesis by blast} - ultimately have ?thesis by blast} - ultimately show ?thesis by blast -qed - -lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')" - shows "numbound0 t' \ n' >0" -proof- - let ?t' = "simpnum t" - let ?g = "numgcd ?t'" - let ?g' = "zgcd n ?g" - {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)} - moreover - { assume nnz: "n \ 0" - {assume "\ ?g > 1" hence ?thesis using prems by (auto simp add: Let_def simp_num_pair_def)} - moreover - {assume g1:"?g>1" hence g0: "?g > 0" by simp - from zgcd0 g1 nnz have gp0: "?g' \ 0" by simp - hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith - hence "?g'= 1 \ ?g' > 1" by arith - moreover {assume "?g'=1" hence ?thesis using prems - by (auto simp add: Let_def simp_num_pair_def)} - moreover {assume g'1:"?g'>1" - have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) - have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) - have gpdgp: "?g' dvd ?g'" by simp - from zdvd_imp_le[OF gpdd np] have g'n: "?g' \ n" . - from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]] - have "n div ?g' >0" by simp - hence ?thesis using prems - by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0)} - ultimately have ?thesis by blast} - ultimately have ?thesis by blast} - ultimately show ?thesis by blast -qed - -consts not:: "fm \ fm" -recdef not "measure size" - "not (NOT p) = p" - "not T = F" - "not F = T" - "not (Lt t) = Ge t" - "not (Le t) = Gt t" - "not (Gt t) = Le t" - "not (Ge t) = Lt t" - "not (Eq t) = NEq t" - "not (NEq t) = Eq t" - "not (Dvd i t) = NDvd i t" - "not (NDvd i t) = Dvd i t" - "not (And p q) = Or (not p) (not q)" - "not (Or p q) = And (not p) (not q)" - "not p = NOT p" -lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)" -by (induct p) auto -lemma not_qf[simp]: "qfree p \ qfree (not p)" -by (induct p, auto) -lemma not_nb[simp]: "bound0 p \ bound0 (not p)" -by (induct p, auto) - -constdefs conj :: "fm \ fm \ fm" - "conj p q \ (if (p = F \ q=F) then F else if p=T then q else if q=T then p else - if p = q then p else And p q)" -lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)" -by (cases "p=F \ q=F",simp_all add: conj_def) (cases p,simp_all) - -lemma conj_qf[simp]: "\qfree p ; qfree q\ \ qfree (conj p q)" -using conj_def by auto -lemma conj_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (conj p q)" -using conj_def by auto - -constdefs disj :: "fm \ fm \ fm" - "disj p q \ (if (p = T \ q=T) then T else if p=F then q else if q=F then p - else if p=q then p else Or p q)" - -lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)" -by (cases "p=T \ q=T",simp_all add: disj_def) (cases p,simp_all) -lemma disj_qf[simp]: "\qfree p ; qfree q\ \ qfree (disj p q)" -using disj_def by auto -lemma disj_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (disj p q)" -using disj_def by auto - -constdefs imp :: "fm \ fm \ fm" - "imp p q \ (if (p = F \ q=T \ p=q) then T else if p=T then q else if q=F then not p - else Imp p q)" -lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)" -by (cases "p=F \ q=T",simp_all add: imp_def) -lemma imp_qf[simp]: "\qfree p ; qfree q\ \ qfree (imp p q)" -using imp_def by (cases "p=F \ q=T",simp_all add: imp_def) -lemma imp_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (imp p q)" -using imp_def by (cases "p=F \ q=T \ p=q",simp_all add: imp_def) - -constdefs iff :: "fm \ fm \ fm" - "iff p q \ (if (p = q) then T else if (p = not q \ not p = q) then F else - if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else - Iff p q)" -lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)" - by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp add:not) -(cases "not p= q", auto simp add:not) -lemma iff_qf[simp]: "\qfree p ; qfree q\ \ qfree (iff p q)" - by (unfold iff_def,cases "p=q", auto) -lemma iff_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (iff p q)" -using iff_def by (unfold iff_def,cases "p=q", auto) - -consts check_int:: "num \ bool" -recdef check_int "measure size" - "check_int (C i) = True" - "check_int (Floor t) = True" - "check_int (Mul i t) = check_int t" - "check_int (Add t s) = (check_int t \ check_int s)" - "check_int (Neg t) = check_int t" - "check_int (CF c t s) = check_int s" - "check_int t = False" -lemma check_int: "check_int t \ isint t bs" -by (induct t, auto simp add: isint_add isint_Floor isint_Mul isint_neg isint_c isint_CF) - -lemma rdvd_left1_int: "real \t\ = t \ 1 rdvd t" - by (simp add: rdvd_def,rule_tac x="\t\" in exI) simp - -lemma rdvd_reduce: - assumes gd:"g dvd d" and gc:"g dvd c" and gp: "g > 0" - shows "real (d::int) rdvd real (c::int)*t = (real (d div g) rdvd real (c div g)*t)" -proof - assume d: "real d rdvd real c * t" - from d rdvd_def obtain k where k_def: "real c * t = real d* real (k::int)" by auto - from gd dvd_def obtain kd where kd_def: "d = g * kd" by auto - from gc dvd_def obtain kc where kc_def: "c = g * kc" by auto - from k_def kd_def kc_def have "real g * real kc * t = real g * real kd * real k" by simp - hence "real kc * t = real kd * real k" using gp by simp - hence th:"real kd rdvd real kc * t" using rdvd_def by blast - from kd_def gp have th':"kd = d div g" by simp - from kc_def gp have "kc = c div g" by simp - with th th' show "real (d div g) rdvd real (c div g) * t" by simp -next - assume d: "real (d div g) rdvd real (c div g) * t" - from gp have gnz: "g \ 0" by simp - thus "real d rdvd real c * t" using d rdvd_mult[OF gnz, where n="d div g" and x="real (c div g) * t"] real_of_int_div[OF gnz gd] real_of_int_div[OF gnz gc] by simp -qed - -constdefs simpdvd:: "int \ num \ (int \ num)" - "simpdvd d t \ - (let g = numgcd t in - if g > 1 then (let g' = zgcd d g in - if g' = 1 then (d, t) - else (d div g',reducecoeffh t g')) - else (d, t))" -lemma simpdvd: - assumes tnz: "nozerocoeff t" and dnz: "d \ 0" - shows "Ifm bs (Dvd (fst (simpdvd d t)) (snd (simpdvd d t))) = Ifm bs (Dvd d t)" -proof- - let ?g = "numgcd t" - let ?g' = "zgcd d ?g" - {assume "\ ?g > 1" hence ?thesis by (simp add: Let_def simpdvd_def)} - moreover - {assume g1:"?g>1" hence g0: "?g > 0" by simp - from zgcd0 g1 dnz have gp0: "?g' \ 0" by simp - hence g'p: "?g' > 0" using zgcd_pos[where i="d" and j="numgcd t"] by arith - hence "?g'= 1 \ ?g' > 1" by arith - moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simpdvd_def)} - moreover {assume g'1:"?g'>1" - from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" .. - let ?tt = "reducecoeffh t ?g'" - let ?t = "Inum bs ?tt" - have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) - have gpdd: "?g' dvd d" by (simp add: zgcd_zdvd1) - have gpdgp: "?g' dvd ?g'" by simp - from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] - have th2:"real ?g' * ?t = Inum bs t" by simp - from prems have "Ifm bs (Dvd (fst (simpdvd d t)) (snd(simpdvd d t))) = Ifm bs (Dvd (d div ?g') ?tt)" - by (simp add: simpdvd_def Let_def) - also have "\ = (real d rdvd (Inum bs t))" - using rdvd_reduce[OF gpdd gpdgp g'p, where t="?t", simplified zdiv_self[OF gp0]] - th2[symmetric] by simp - finally have ?thesis by simp } - ultimately have ?thesis by blast - } - ultimately show ?thesis by blast -qed - -consts simpfm :: "fm \ fm" -recdef simpfm "measure fmsize" - "simpfm (And p q) = conj (simpfm p) (simpfm q)" - "simpfm (Or p q) = disj (simpfm p) (simpfm q)" - "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" - "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" - "simpfm (NOT p) = not (simpfm p)" - "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \ if (v < 0) then T else F - | _ \ Lt (reducecoeff a'))" - "simpfm (Le a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Le (reducecoeff a'))" - "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \ if (v > 0) then T else F | _ \ Gt (reducecoeff a'))" - "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Ge (reducecoeff a'))" - "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \ if (v = 0) then T else F | _ \ Eq (reducecoeff a'))" - "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ NEq (reducecoeff a'))" - "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a) - else if (abs i = 1) \ check_int a then T - else let a' = simpnum a in case a' of C v \ if (i dvd v) then T else F | _ \ (let (d,t) = simpdvd i a' in Dvd d t))" - "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a) - else if (abs i = 1) \ check_int a then F - else let a' = simpnum a in case a' of C v \ if (\(i dvd v)) then T else F | _ \ (let (d,t) = simpdvd i a' in NDvd d t))" - "simpfm p = p" - -lemma simpfm[simp]: "Ifm bs (simpfm p) = Ifm bs p" -proof(induct p rule: simpfm.induct) - case (6 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume H:"\ (\ v. ?sa = C v)" - let ?g = "numgcd ?sa" - let ?rsa = "reducecoeff ?sa" - let ?r = "Inum bs ?rsa" - have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) - {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} - with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) - hence gp: "real ?g > 0" by simp - have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) - with sa have "Inum bs a < 0 = (real ?g * ?r < real ?g * 0)" by simp - also have "\ = (?r < 0)" using gp - by (simp only: mult_less_cancel_left) simp - finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} - ultimately show ?case by blast -next - case (7 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume H:"\ (\ v. ?sa = C v)" - let ?g = "numgcd ?sa" - let ?rsa = "reducecoeff ?sa" - let ?r = "Inum bs ?rsa" - have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) - {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} - with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) - hence gp: "real ?g > 0" by simp - have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) - with sa have "Inum bs a \ 0 = (real ?g * ?r \ real ?g * 0)" by simp - also have "\ = (?r \ 0)" using gp - by (simp only: mult_le_cancel_left) simp - finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} - ultimately show ?case by blast -next - case (8 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume H:"\ (\ v. ?sa = C v)" - let ?g = "numgcd ?sa" - let ?rsa = "reducecoeff ?sa" - let ?r = "Inum bs ?rsa" - have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) - {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} - with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) - hence gp: "real ?g > 0" by simp - have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) - with sa have "Inum bs a > 0 = (real ?g * ?r > real ?g * 0)" by simp - also have "\ = (?r > 0)" using gp - by (simp only: mult_less_cancel_left) simp - finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} - ultimately show ?case by blast -next - case (9 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume H:"\ (\ v. ?sa = C v)" - let ?g = "numgcd ?sa" - let ?rsa = "reducecoeff ?sa" - let ?r = "Inum bs ?rsa" - have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) - {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} - with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) - hence gp: "real ?g > 0" by simp - have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) - with sa have "Inum bs a \ 0 = (real ?g * ?r \ real ?g * 0)" by simp - also have "\ = (?r \ 0)" using gp - by (simp only: mult_le_cancel_left) simp - finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} - ultimately show ?case by blast -next - case (10 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume H:"\ (\ v. ?sa = C v)" - let ?g = "numgcd ?sa" - let ?rsa = "reducecoeff ?sa" - let ?r = "Inum bs ?rsa" - have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) - {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} - with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) - hence gp: "real ?g > 0" by simp - have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) - with sa have "Inum bs a = 0 = (real ?g * ?r = 0)" by simp - also have "\ = (?r = 0)" using gp - by (simp add: mult_eq_0_iff) - finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} - ultimately show ?case by blast -next - case (11 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume H:"\ (\ v. ?sa = C v)" - let ?g = "numgcd ?sa" - let ?rsa = "reducecoeff ?sa" - let ?r = "Inum bs ?rsa" - have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz) - {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto} - with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto) - hence gp: "real ?g > 0" by simp - have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff) - with sa have "Inum bs a \ 0 = (real ?g * ?r \ 0)" by simp - also have "\ = (?r \ 0)" using gp - by (simp add: mult_eq_0_iff) - finally have ?case using H by (cases "?sa" , simp_all add: Let_def)} - ultimately show ?case by blast -next - case (12 i a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - have "i=0 \ (abs i = 1 \ check_int a) \ (i\0 \ ((abs i \ 1) \ (\ check_int a)))" by auto - {assume "i=0" hence ?case using "12.hyps" by (simp add: rdvd_left_0_eq Let_def)} - moreover - {assume ai1: "abs i = 1" and ai: "check_int a" - hence "i=1 \ i= - 1" by arith - moreover {assume i1: "i = 1" - from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] - have ?case using i1 ai by simp } - moreover {assume i1: "i = - 1" - from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] - rdvd_abs1[where d="- 1" and t="Inum bs a"] - have ?case using i1 ai by simp } - ultimately have ?case by blast} - moreover - {assume inz: "i\0" and cond: "(abs i \ 1) \ (\ check_int a)" - {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond - by (cases "abs i = 1", auto simp add: int_rdvd_iff) } - moreover {assume H:"\ (\ v. ?sa = C v)" - hence th: "simpfm (Dvd i a) = Dvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond by (cases ?sa, auto simp add: Let_def split_def) - from simpnum_nz have nz:"nozerocoeff ?sa" by simp - from simpdvd [OF nz inz] th have ?case using sa by simp} - ultimately have ?case by blast} - ultimately show ?case by blast -next - case (13 i a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp - have "i=0 \ (abs i = 1 \ check_int a) \ (i\0 \ ((abs i \ 1) \ (\ check_int a)))" by auto - {assume "i=0" hence ?case using "13.hyps" by (simp add: rdvd_left_0_eq Let_def)} - moreover - {assume ai1: "abs i = 1" and ai: "check_int a" - hence "i=1 \ i= - 1" by arith - moreover {assume i1: "i = 1" - from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] - have ?case using i1 ai by simp } - moreover {assume i1: "i = - 1" - from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] - rdvd_abs1[where d="- 1" and t="Inum bs a"] - have ?case using i1 ai by simp } - ultimately have ?case by blast} - moreover - {assume inz: "i\0" and cond: "(abs i \ 1) \ (\ check_int a)" - {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond - by (cases "abs i = 1", auto simp add: int_rdvd_iff) } - moreover {assume H:"\ (\ v. ?sa = C v)" - hence th: "simpfm (NDvd i a) = NDvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond - by (cases ?sa, auto simp add: Let_def split_def) - from simpnum_nz have nz:"nozerocoeff ?sa" by simp - from simpdvd [OF nz inz] th have ?case using sa by simp} - ultimately have ?case by blast} - ultimately show ?case by blast -qed (induct p rule: simpfm.induct, simp_all) - -lemma simpdvd_numbound0: "numbound0 t \ numbound0 (snd (simpdvd d t))" - by (simp add: simpdvd_def Let_def split_def reducecoeffh_numbound0) - -lemma simpfm_bound0[simp]: "bound0 p \ bound0 (simpfm p)" -proof(induct p rule: simpfm.induct) - case (6 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) -next - case (7 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) -next - case (8 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) -next - case (9 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) -next - case (10 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) -next - case (11 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0) -next - case (12 i a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def) -next - case (13 i a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def) -qed(auto simp add: disj_def imp_def iff_def conj_def) - -lemma simpfm_qf[simp]: "qfree p \ qfree (simpfm p)" -by (induct p rule: simpfm.induct, auto simp add: Let_def) -(case_tac "simpnum a",auto simp add: split_def Let_def)+ - - - (* Generic quantifier elimination *) - -constdefs list_conj :: "fm list \ fm" - "list_conj ps \ foldr conj ps T" -lemma list_conj: "Ifm bs (list_conj ps) = (\p\ set ps. Ifm bs p)" - by (induct ps, auto simp add: list_conj_def) -lemma list_conj_qf: " \p\ set ps. qfree p \ qfree (list_conj ps)" - by (induct ps, auto simp add: list_conj_def) -lemma list_conj_nb: " \p\ set ps. bound0 p \ bound0 (list_conj ps)" - by (induct ps, auto simp add: list_conj_def) -constdefs CJNB:: "(fm \ fm) \ fm \ fm" - "CJNB f p \ (let cjs = conjuncts p ; (yes,no) = partition bound0 cjs - in conj (decr (list_conj yes)) (f (list_conj no)))" - -lemma CJNB_qe: - assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" - shows "\ bs p. qfree p \ qfree (CJNB qe p) \ (Ifm bs ((CJNB qe p)) = Ifm bs (E p))" -proof(clarify) - fix bs p - assume qfp: "qfree p" - let ?cjs = "conjuncts p" - let ?yes = "fst (partition bound0 ?cjs)" - let ?no = "snd (partition bound0 ?cjs)" - let ?cno = "list_conj ?no" - let ?cyes = "list_conj ?yes" - have part: "partition bound0 ?cjs = (?yes,?no)" by simp - from partition_P[OF part] have "\ q\ set ?yes. bound0 q" by blast - hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb) - hence yes_qf: "qfree (decr ?cyes )" by (simp add: decr_qf) - from conjuncts_qf[OF qfp] partition_set[OF part] - have " \q\ set ?no. qfree q" by auto - hence no_qf: "qfree ?cno"by (simp add: list_conj_qf) - with qe have cno_qf:"qfree (qe ?cno )" - and noE: "Ifm bs (qe ?cno) = Ifm bs (E ?cno)" by blast+ - from cno_qf yes_qf have qf: "qfree (CJNB qe p)" - by (simp add: CJNB_def Let_def conj_qf split_def) - {fix bs - from conjuncts have "Ifm bs p = (\q\ set ?cjs. Ifm bs q)" by blast - also have "\ = ((\q\ set ?yes. Ifm bs q) \ (\q\ set ?no. Ifm bs q))" - using partition_set[OF part] by auto - finally have "Ifm bs p = ((Ifm bs ?cyes) \ (Ifm bs ?cno))" using list_conj by simp} - hence "Ifm bs (E p) = (\x. (Ifm (x#bs) ?cyes) \ (Ifm (x#bs) ?cno))" by simp - also fix y have "\ = (\x. (Ifm (y#bs) ?cyes) \ (Ifm (x#bs) ?cno))" - using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast - also have "\ = (Ifm bs (decr ?cyes) \ Ifm bs (E ?cno))" - by (auto simp add: decr[OF yes_nb]) - also have "\ = (Ifm bs (conj (decr ?cyes) (qe ?cno)))" - using qe[rule_format, OF no_qf] by auto - finally have "Ifm bs (E p) = Ifm bs (CJNB qe p)" - by (simp add: Let_def CJNB_def split_def) - with qf show "qfree (CJNB qe p) \ Ifm bs (CJNB qe p) = Ifm bs (E p)" by blast -qed - -consts qelim :: "fm \ (fm \ fm) \ fm" -recdef qelim "measure fmsize" - "qelim (E p) = (\ qe. DJ (CJNB qe) (qelim p qe))" - "qelim (A p) = (\ qe. not (qe ((qelim (NOT p) qe))))" - "qelim (NOT p) = (\ qe. not (qelim p qe))" - "qelim (And p q) = (\ qe. conj (qelim p qe) (qelim q qe))" - "qelim (Or p q) = (\ qe. disj (qelim p qe) (qelim q qe))" - "qelim (Imp p q) = (\ qe. disj (qelim (NOT p) qe) (qelim q qe))" - "qelim (Iff p q) = (\ qe. iff (qelim p qe) (qelim q qe))" - "qelim p = (\ y. simpfm p)" - -lemma qelim_ci: - assumes qe_inv: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" - shows "\ bs. qfree (qelim p qe) \ (Ifm bs (qelim p qe) = Ifm bs p)" -using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]] -by(induct p rule: qelim.induct) -(auto simp del: simpfm.simps) - - -text {* The @{text "\"} Part *} -text{* Linearity for fm where Bound 0 ranges over @{text "\"} *} -consts - zsplit0 :: "num \ int \ num" (* splits the bounded from the unbounded part*) -recdef zsplit0 "measure num_size" - "zsplit0 (C c) = (0,C c)" - "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))" - "zsplit0 (CN n c a) = zsplit0 (Add (Mul c (Bound n)) a)" - "zsplit0 (CF c a b) = zsplit0 (Add (Mul c (Floor a)) b)" - "zsplit0 (Neg a) = (let (i',a') = zsplit0 a in (-i', Neg a'))" - "zsplit0 (Add a b) = (let (ia,a') = zsplit0 a ; - (ib,b') = zsplit0 b - in (ia+ib, Add a' b'))" - "zsplit0 (Sub a b) = (let (ia,a') = zsplit0 a ; - (ib,b') = zsplit0 b - in (ia-ib, Sub a' b'))" - "zsplit0 (Mul i a) = (let (i',a') = zsplit0 a in (i*i', Mul i a'))" - "zsplit0 (Floor a) = (let (i',a') = zsplit0 a in (i',Floor a'))" -(hints simp add: Let_def) - -lemma zsplit0_I: - shows "\ n a. zsplit0 t = (n,a) \ (Inum ((real (x::int)) #bs) (CN 0 n a) = Inum (real x #bs) t) \ numbound0 a" - (is "\ n a. ?S t = (n,a) \ (?I x (CN 0 n a) = ?I x t) \ ?N a") -proof(induct t rule: zsplit0.induct) - case (1 c n a) thus ?case by auto -next - case (2 m n a) thus ?case by (cases "m=0") auto -next - case (3 n i a n a') thus ?case by auto -next - case (4 c a b n a') thus ?case by auto -next - case (5 t n a) - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \ n=-?nt" using prems - by (simp add: Let_def split_def) - from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - from th2[simplified] th[simplified] show ?case by simp -next - case (6 s t n a) - let ?ns = "fst (zsplit0 s)" - let ?as = "snd (zsplit0 s)" - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abjs: "zsplit0 s = (?ns,?as)" by simp - moreover have abjt: "zsplit0 t = (?nt,?at)" by simp - ultimately have th: "a=Add ?as ?at \ n=?ns + ?nt" using prems - by (simp add: Let_def split_def) - from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast - from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (real x # bs) (CN 0 xa xb) = Inum (real x # bs) t \ numbound0 xb)" by simp - with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast - from th3[simplified] th2[simplified] th[simplified] show ?case - by (simp add: left_distrib) -next - case (7 s t n a) - let ?ns = "fst (zsplit0 s)" - let ?as = "snd (zsplit0 s)" - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abjs: "zsplit0 s = (?ns,?as)" by simp - moreover have abjt: "zsplit0 t = (?nt,?at)" by simp - ultimately have th: "a=Sub ?as ?at \ n=?ns - ?nt" using prems - by (simp add: Let_def split_def) - from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast - from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (real x # bs) (CN 0 xa xb) = Inum (real x # bs) t \ numbound0 xb)" by simp - with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast - from th3[simplified] th2[simplified] th[simplified] show ?case - by (simp add: left_diff_distrib) -next - case (8 i t n a) - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \ n=i*?nt" using prems - by (simp add: Let_def split_def) - from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - hence " ?I x (Mul i t) = (real i) * ?I x (CN 0 ?nt ?at)" by simp - also have "\ = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: right_distrib) - finally show ?case using th th2 by simp -next - case (9 t n a) - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a= Floor ?at \ n=?nt" using prems - by (simp add: Let_def split_def) - from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - hence na: "?N a" using th by simp - have th': "(real ?nt)*(real x) = real (?nt * x)" by simp - have "?I x (Floor t) = ?I x (Floor (CN 0 ?nt ?at))" using th2 by simp - also have "\ = real (floor ((real ?nt)* real(x) + ?I x ?at))" by simp - also have "\ = real (floor (?I x ?at + real (?nt* x)))" by (simp add: add_ac) - also have "\ = real (floor (?I x ?at) + (?nt* x))" - using floor_add[where x="?I x ?at" and a="?nt* x"] by simp - also have "\ = real (?nt)*(real x) + real (floor (?I x ?at))" by (simp add: add_ac) - finally have "?I x (Floor t) = ?I x (CN 0 n a)" using th by simp - with na show ?case by simp -qed - -consts - iszlfm :: "fm \ real list \ bool" (* Linearity test for fm *) - zlfm :: "fm \ fm" (* Linearity transformation for fm *) -recdef iszlfm "measure size" - "iszlfm (And p q) = (\ bs. iszlfm p bs \ iszlfm q bs)" - "iszlfm (Or p q) = (\ bs. iszlfm p bs \ iszlfm q bs)" - "iszlfm (Eq (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" - "iszlfm (NEq (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" - "iszlfm (Lt (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" - "iszlfm (Le (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" - "iszlfm (Gt (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" - "iszlfm (Ge (CN 0 c e)) = (\ bs. c>0 \ numbound0 e \ isint e bs)" - "iszlfm (Dvd i (CN 0 c e)) = - (\ bs. c>0 \ i>0 \ numbound0 e \ isint e bs)" - "iszlfm (NDvd i (CN 0 c e))= - (\ bs. c>0 \ i>0 \ numbound0 e \ isint e bs)" - "iszlfm p = (\ bs. isatom p \ (bound0 p))" - -lemma zlin_qfree: "iszlfm p bs \ qfree p" - by (induct p rule: iszlfm.induct) auto - -lemma iszlfm_gen: - assumes lp: "iszlfm p (x#bs)" - shows "\ y. iszlfm p (y#bs)" -proof - fix y - show "iszlfm p (y#bs)" - using lp - by(induct p rule: iszlfm.induct, simp_all add: numbound0_gen[rule_format, where x="x" and y="y"]) -qed - -lemma conj_zl[simp]: "iszlfm p bs \ iszlfm q bs \ iszlfm (conj p q) bs" - using conj_def by (cases p,auto) -lemma disj_zl[simp]: "iszlfm p bs \ iszlfm q bs \ iszlfm (disj p q) bs" - using disj_def by (cases p,auto) -lemma not_zl[simp]: "iszlfm p bs \ iszlfm (not p) bs" - by (induct p rule:iszlfm.induct ,auto) - -recdef zlfm "measure fmsize" - "zlfm (And p q) = conj (zlfm p) (zlfm q)" - "zlfm (Or p q) = disj (zlfm p) (zlfm q)" - "zlfm (Imp p q) = disj (zlfm (NOT p)) (zlfm q)" - "zlfm (Iff p q) = disj (conj (zlfm p) (zlfm q)) (conj (zlfm (NOT p)) (zlfm (NOT q)))" - "zlfm (Lt a) = (let (c,r) = zsplit0 a in - if c=0 then Lt r else - if c>0 then Or (Lt (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r))) - else Or (Gt (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))" - "zlfm (Le a) = (let (c,r) = zsplit0 a in - if c=0 then Le r else - if c>0 then Or (Le (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r))) - else Or (Ge (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))" - "zlfm (Gt a) = (let (c,r) = zsplit0 a in - if c=0 then Gt r else - if c>0 then Or (Gt (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) - else Or (Lt (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))" - "zlfm (Ge a) = (let (c,r) = zsplit0 a in - if c=0 then Ge r else - if c>0 then Or (Ge (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) - else Or (Le (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))" - "zlfm (Eq a) = (let (c,r) = zsplit0 a in - if c=0 then Eq r else - if c>0 then (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Eq (Add (Floor (Neg r)) r))) - else (And (Eq (CN 0 (-c) (Floor (Neg r)))) (Eq (Add (Floor (Neg r)) r))))" - "zlfm (NEq a) = (let (c,r) = zsplit0 a in - if c=0 then NEq r else - if c>0 then (Or (NEq (CN 0 c (Neg (Floor (Neg r))))) (NEq (Add (Floor (Neg r)) r))) - else (Or (NEq (CN 0 (-c) (Floor (Neg r)))) (NEq (Add (Floor (Neg r)) r))))" - "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a) - else (let (c,r) = zsplit0 a in - if c=0 then Dvd (abs i) r else - if c>0 then And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 c (Floor r))) - else And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 (-c) (Neg (Floor r))))))" - "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a) - else (let (c,r) = zsplit0 a in - if c=0 then NDvd (abs i) r else - if c>0 then Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 c (Floor r))) - else Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 (-c) (Neg (Floor r))))))" - "zlfm (NOT (And p q)) = disj (zlfm (NOT p)) (zlfm (NOT q))" - "zlfm (NOT (Or p q)) = conj (zlfm (NOT p)) (zlfm (NOT q))" - "zlfm (NOT (Imp p q)) = conj (zlfm p) (zlfm (NOT q))" - "zlfm (NOT (Iff p q)) = disj (conj(zlfm p) (zlfm(NOT q))) (conj (zlfm(NOT p)) (zlfm q))" - "zlfm (NOT (NOT p)) = zlfm p" - "zlfm (NOT T) = F" - "zlfm (NOT F) = T" - "zlfm (NOT (Lt a)) = zlfm (Ge a)" - "zlfm (NOT (Le a)) = zlfm (Gt a)" - "zlfm (NOT (Gt a)) = zlfm (Le a)" - "zlfm (NOT (Ge a)) = zlfm (Lt a)" - "zlfm (NOT (Eq a)) = zlfm (NEq a)" - "zlfm (NOT (NEq a)) = zlfm (Eq a)" - "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)" - "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)" - "zlfm p = p" (hints simp add: fmsize_pos) - -lemma split_int_less_real: - "(real (a::int) < b) = (a < floor b \ (a = floor b \ real (floor b) < b))" -proof( auto) - assume alb: "real a < b" and agb: "\ a < floor b" - from agb have "floor b \ a" by simp hence th: "b < real a + 1" by (simp only: floor_le_eq) - from floor_eq[OF alb th] show "a= floor b" by simp -next - assume alb: "a < floor b" - hence "real a < real (floor b)" by simp - moreover have "real (floor b) \ b" by simp ultimately show "real a < b" by arith -qed - -lemma split_int_less_real': - "(real (a::int) + b < 0) = (real a - real (floor(-b)) < 0 \ (real a - real (floor (-b)) = 0 \ real (floor (-b)) + b < 0))" -proof- - have "(real a + b <0) = (real a < -b)" by arith - with split_int_less_real[where a="a" and b="-b"] show ?thesis by arith -qed - -lemma split_int_gt_real': - "(real (a::int) + b > 0) = (real a + real (floor b) > 0 \ (real a + real (floor b) = 0 \ real (floor b) - b < 0))" -proof- - have th: "(real a + b >0) = (real (-a) + (-b)< 0)" by arith - show ?thesis using myless[rule_format, where b="real (floor b)"] - by (simp only:th split_int_less_real'[where a="-a" and b="-b"]) - (simp add: algebra_simps diff_def[symmetric],arith) -qed - -lemma split_int_le_real: - "(real (a::int) \ b) = (a \ floor b \ (a = floor b \ real (floor b) < b))" -proof( auto) - assume alb: "real a \ b" and agb: "\ a \ floor b" - from alb have "floor (real a) \ floor b " by (simp only: floor_mono2) - hence "a \ floor b" by simp with agb show "False" by simp -next - assume alb: "a \ floor b" - hence "real a \ real (floor b)" by (simp only: floor_mono2) - also have "\\ b" by simp finally show "real a \ b" . -qed - -lemma split_int_le_real': - "(real (a::int) + b \ 0) = (real a - real (floor(-b)) \ 0 \ (real a - real (floor (-b)) = 0 \ real (floor (-b)) + b < 0))" -proof- - have "(real a + b \0) = (real a \ -b)" by arith - with split_int_le_real[where a="a" and b="-b"] show ?thesis by arith -qed - -lemma split_int_ge_real': - "(real (a::int) + b \ 0) = (real a + real (floor b) \ 0 \ (real a + real (floor b) = 0 \ real (floor b) - b < 0))" -proof- - have th: "(real a + b \0) = (real (-a) + (-b) \ 0)" by arith - show ?thesis by (simp only: th split_int_le_real'[where a="-a" and b="-b"]) - (simp add: algebra_simps diff_def[symmetric],arith) -qed - -lemma split_int_eq_real: "(real (a::int) = b) = ( a = floor b \ b = real (floor b))" (is "?l = ?r") -by auto - -lemma split_int_eq_real': "(real (a::int) + b = 0) = ( a - floor (-b) = 0 \ real (floor (-b)) + b = 0)" (is "?l = ?r") -proof- - have "?l = (real a = -b)" by arith - with split_int_eq_real[where a="a" and b="-b"] show ?thesis by simp arith -qed - -lemma zlfm_I: - assumes qfp: "qfree p" - shows "(Ifm (real i #bs) (zlfm p) = Ifm (real i# bs) p) \ iszlfm (zlfm p) (real (i::int) #bs)" - (is "(?I (?l p) = ?I p) \ ?L (?l p)") -using qfp -proof(induct p rule: zlfm.induct) - case (5 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith - moreover - {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] - by (cases "?r", simp_all add: Let_def split_def,case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Lt a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def) - also have "\ = (?I (?l (Lt a)))" apply (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) by (simp add: Ia cp cnz Let_def split_def diff_def) - finally have ?case using l by simp} - moreover - {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Lt a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def) - also from cn cnz have "\ = (?I (?l (Lt a)))" by (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith) - finally have ?case using l by simp} - ultimately show ?case by blast -next - case (6 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith - moreover - {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat",simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Le a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Le a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) - also have "\ = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def) - finally have ?case using l by simp} - moreover - {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Le a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Le a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) - also from cn cnz have "\ = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac ,arith) - finally have ?case using l by simp} - ultimately show ?case by blast -next - case (7 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith - moreover - {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Gt a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def) - also have "\ = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def) - finally have ?case using l by simp} - moreover - {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Gt a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def) - also from cn cnz have "\ = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith) - finally have ?case using l by simp} - ultimately show ?case by blast -next - case (8 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith - moreover - {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Ge a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Ge a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) - also have "\ = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def diff_def) - finally have ?case using l by simp} - moreover - {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Ge a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Ge a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) - also from cn cnz have "\ = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def diff_def[symmetric] add_ac, arith) - finally have ?case using l by simp} - ultimately show ?case by blast -next - case (9 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith - moreover - {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (Eq a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def) - also have "\ = (?I (?l (Eq a)))" using cp cnz by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult) - finally have ?case using l by simp} - moreover - {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (Eq a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def) - also from cn cnz have "\ = (?I (?l (Eq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult,arith) - finally have ?case using l by simp} - ultimately show ?case by blast -next - case (10 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "?c = 0 \ (?c >0 \ ?c\0) \ (?c<0 \ ?c\0)" by arith - moreover - {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" hence l: "?L (?l (NEq a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (NEq a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) - also have "\ = (?I (?l (NEq a)))" using cp cnz by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult) - finally have ?case using l by simp} - moreover - {assume cn: "?c < 0" and cnz: "?c\0" hence l: "?L (?l (NEq a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (NEq a) = (real (?c * i) + (?N ?r) \ 0)" using Ia by (simp add: Let_def split_def) - also from cn cnz have "\ = (?I (?l (NEq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia real_of_int_mult[symmetric] del: real_of_int_mult,arith) - finally have ?case using l by simp} - ultimately show ?case by blast -next - case (11 j a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0 \ ?c\0) \ (j\ 0 \ ?c<0 \ ?c\0)" by arith - moreover - {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def) - hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)} - moreover - {assume "?c=0" and "j\0" hence ?case - using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" - using Ia by (simp add: Let_def split_def) - also have "\ = (real (abs j) rdvd real (?c*i) + (?N ?r))" - by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp - also have "\ = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ - (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" - by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) - also have "\ = (?I (?l (Dvd j a)))" using cp cnz jnz - by (simp add: Let_def split_def int_rdvd_iff[symmetric] - del: real_of_int_mult) (auto simp add: add_ac) - finally have ?case using l jnz by simp } - moreover - {assume cn: "?c < 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" - using Ia by (simp add: Let_def split_def) - also have "\ = (real (abs j) rdvd real (?c*i) + (?N ?r))" - by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp - also have "\ = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ - (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" - by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) - also have "\ = (?I (?l (Dvd j a)))" using cn cnz jnz - using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric] - by (simp add: Let_def split_def int_rdvd_iff[symmetric] - del: real_of_int_mult) (auto simp add: add_ac) - finally have ?case using l jnz by blast } - ultimately show ?case by blast -next - case (12 j a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (real i#bs) t" - have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0 \ ?c\0) \ (j\ 0 \ ?c<0 \ ?c\0)" by arith - moreover - {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def) - hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)} - moreover - {assume "?c=0" and "j\0" hence ?case - using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"] - by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)} - moreover - {assume cp: "?c > 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (NDvd j a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (NDvd j a) = (\ (real j rdvd (real (?c * i) + (?N ?r))))" - using Ia by (simp add: Let_def split_def) - also have "\ = (\ (real (abs j) rdvd real (?c*i) + (?N ?r)))" - by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp - also have "\ = (\ ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ - (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" - by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) - also have "\ = (?I (?l (NDvd j a)))" using cp cnz jnz - by (simp add: Let_def split_def int_rdvd_iff[symmetric] - del: real_of_int_mult) (auto simp add: add_ac) - finally have ?case using l jnz by simp } - moreover - {assume cn: "?c < 0" and cnz: "?c\0" and jnz: "j\0" hence l: "?L (?l (NDvd j a))" - by (simp add: nb Let_def split_def isint_Floor isint_neg) - have "?I (NDvd j a) = (\ (real j rdvd (real (?c * i) + (?N ?r))))" - using Ia by (simp add: Let_def split_def) - also have "\ = (\ (real (abs j) rdvd real (?c*i) + (?N ?r)))" - by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp - also have "\ = (\ ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \ - (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" - by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac) - also have "\ = (?I (?l (NDvd j a)))" using cn cnz jnz - using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric] - by (simp add: Let_def split_def int_rdvd_iff[symmetric] - del: real_of_int_mult) (auto simp add: add_ac) - finally have ?case using l jnz by blast } - ultimately show ?case by blast -qed auto - -text{* plusinf : Virtual substitution of @{text "+\"} - minusinf: Virtual substitution of @{text "-\"} - @{text "\"} Compute lcm @{text "d| Dvd d c*x+t \ p"} - @{text "d\"} checks if a given l divides all the ds above*} - -consts - plusinf:: "fm \ fm" - minusinf:: "fm \ fm" - \ :: "fm \ int" - d\ :: "fm \ int \ bool" - -recdef minusinf "measure size" - "minusinf (And p q) = conj (minusinf p) (minusinf q)" - "minusinf (Or p q) = disj (minusinf p) (minusinf q)" - "minusinf (Eq (CN 0 c e)) = F" - "minusinf (NEq (CN 0 c e)) = T" - "minusinf (Lt (CN 0 c e)) = T" - "minusinf (Le (CN 0 c e)) = T" - "minusinf (Gt (CN 0 c e)) = F" - "minusinf (Ge (CN 0 c e)) = F" - "minusinf p = p" - -lemma minusinf_qfree: "qfree p \ qfree (minusinf p)" - by (induct p rule: minusinf.induct, auto) - -recdef plusinf "measure size" - "plusinf (And p q) = conj (plusinf p) (plusinf q)" - "plusinf (Or p q) = disj (plusinf p) (plusinf q)" - "plusinf (Eq (CN 0 c e)) = F" - "plusinf (NEq (CN 0 c e)) = T" - "plusinf (Lt (CN 0 c e)) = F" - "plusinf (Le (CN 0 c e)) = F" - "plusinf (Gt (CN 0 c e)) = T" - "plusinf (Ge (CN 0 c e)) = T" - "plusinf p = p" - -recdef \ "measure size" - "\ (And p q) = zlcm (\ p) (\ q)" - "\ (Or p q) = zlcm (\ p) (\ q)" - "\ (Dvd i (CN 0 c e)) = i" - "\ (NDvd i (CN 0 c e)) = i" - "\ p = 1" - -recdef d\ "measure size" - "d\ (And p q) = (\ d. d\ p d \ d\ q d)" - "d\ (Or p q) = (\ d. d\ p d \ d\ q d)" - "d\ (Dvd i (CN 0 c e)) = (\ d. i dvd d)" - "d\ (NDvd i (CN 0 c e)) = (\ d. i dvd d)" - "d\ p = (\ d. True)" - -lemma delta_mono: - assumes lin: "iszlfm p bs" - and d: "d dvd d'" - and ad: "d\ p d" - shows "d\ p d'" - using lin ad d -proof(induct p rule: iszlfm.induct) - case (9 i c e) thus ?case using d - by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) -next - case (10 i c e) thus ?case using d - by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) -qed simp_all - -lemma \ : assumes lin:"iszlfm p bs" - shows "d\ p (\ p) \ \ p >0" -using lin -proof (induct p rule: iszlfm.induct) - case (1 p q) - let ?d = "\ (And p q)" - from prems zlcm_pos have dp: "?d >0" by simp - have d1: "\ p dvd \ (And p q)" using prems by simp - hence th: "d\ p ?d" - using delta_mono prems by (auto simp del: dvd_zlcm_self1) - have "\ q dvd \ (And p q)" using prems by simp - hence th': "d\ q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2) - from th th' dp show ?case by simp -next - case (2 p q) - let ?d = "\ (And p q)" - from prems zlcm_pos have dp: "?d >0" by simp - have "\ p dvd \ (And p q)" using prems by simp hence th: "d\ p ?d" using delta_mono prems - by (auto simp del: dvd_zlcm_self1) - have "\ q dvd \ (And p q)" using prems by simp hence th': "d\ q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2) - from th th' dp show ?case by simp -qed simp_all - - -lemma minusinf_inf: - assumes linp: "iszlfm p (a # bs)" - shows "\ (z::int). \ x < z. Ifm ((real x)#bs) (minusinf p) = Ifm ((real x)#bs) p" - (is "?P p" is "\ (z::int). \ x < z. ?I x (?M p) = ?I x p") -using linp -proof (induct p rule: minusinf.induct) - case (1 f g) - from prems have "?P f" by simp - then obtain z1 where z1_def: "\ x < z1. ?I x (?M f) = ?I x f" by blast - from prems have "?P g" by simp - then obtain z2 where z2_def: "\ x < z2. ?I x (?M g) = ?I x g" by blast - let ?z = "min z1 z2" - from z1_def z2_def have "\ x < ?z. ?I x (?M (And f g)) = ?I x (And f g)" by simp - thus ?case by blast -next - case (2 f g) from prems have "?P f" by simp - then obtain z1 where z1_def: "\ x < z1. ?I x (?M f) = ?I x f" by blast - from prems have "?P g" by simp - then obtain z2 where z2_def: "\ x < z2. ?I x (?M g) = ?I x g" by blast - let ?z = "min z1 z2" - from z1_def z2_def have "\ x < ?z. ?I x (?M (Or f g)) = ?I x (Or f g)" by simp - thus ?case by blast -next - case (3 c e) - from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp - from prems have nbe: "numbound0 e" by simp - fix y - have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Eq (CN 0 c e))) = ?I x (Eq (CN 0 c e))" - proof (simp add: less_floor_eq , rule allI, rule impI) - fix x - assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" - hence th1:"real x < - (Inum (y # bs) e / real c)" by simp - with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" - by (simp only: real_mult_less_mono2[OF rcpos th1]) - hence "real c * real x + Inum (y # bs) e \ 0"using rcpos by simp - thus "real c * real x + Inum (real x # bs) e \ 0" - using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] by simp - qed - thus ?case by blast -next - case (4 c e) - from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp - from prems have nbe: "numbound0 e" by simp - fix y - have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (NEq (CN 0 c e))) = ?I x (NEq (CN 0 c e))" - proof (simp add: less_floor_eq , rule allI, rule impI) - fix x - assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" - hence th1:"real x < - (Inum (y # bs) e / real c)" by simp - with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" - by (simp only: real_mult_less_mono2[OF rcpos th1]) - hence "real c * real x + Inum (y # bs) e \ 0"using rcpos by simp - thus "real c * real x + Inum (real x # bs) e \ 0" - using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] by simp - qed - thus ?case by blast -next - case (5 c e) - from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp - from prems have nbe: "numbound0 e" by simp - fix y - have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Lt (CN 0 c e))) = ?I x (Lt (CN 0 c e))" - proof (simp add: less_floor_eq , rule allI, rule impI) - fix x - assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" - hence th1:"real x < - (Inum (y # bs) e / real c)" by simp - with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" - by (simp only: real_mult_less_mono2[OF rcpos th1]) - thus "real c * real x + Inum (real x # bs) e < 0" - using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp - qed - thus ?case by blast -next - case (6 c e) - from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp - from prems have nbe: "numbound0 e" by simp - fix y - have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Le (CN 0 c e))) = ?I x (Le (CN 0 c e))" - proof (simp add: less_floor_eq , rule allI, rule impI) - fix x - assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" - hence th1:"real x < - (Inum (y # bs) e / real c)" by simp - with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" - by (simp only: real_mult_less_mono2[OF rcpos th1]) - thus "real c * real x + Inum (real x # bs) e \ 0" - using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp - qed - thus ?case by blast -next - case (7 c e) - from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp - from prems have nbe: "numbound0 e" by simp - fix y - have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Gt (CN 0 c e))) = ?I x (Gt (CN 0 c e))" - proof (simp add: less_floor_eq , rule allI, rule impI) - fix x - assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" - hence th1:"real x < - (Inum (y # bs) e / real c)" by simp - with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" - by (simp only: real_mult_less_mono2[OF rcpos th1]) - thus "\ (real c * real x + Inum (real x # bs) e>0)" - using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp - qed - thus ?case by blast -next - case (8 c e) - from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp - from prems have nbe: "numbound0 e" by simp - fix y - have "\ x < (floor (- (Inum (y#bs) e) / (real c))). ?I x (?M (Ge (CN 0 c e))) = ?I x (Ge (CN 0 c e))" - proof (simp add: less_floor_eq , rule allI, rule impI) - fix x - assume A: "real x + (1\real) \ - (Inum (y # bs) e / real c)" - hence th1:"real x < - (Inum (y # bs) e / real c)" by simp - with rcpos have "(real c)*(real x) < (real c)*(- (Inum (y # bs) e / real c))" - by (simp only: real_mult_less_mono2[OF rcpos th1]) - thus "\ real c * real x + Inum (real x # bs) e \ 0" - using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp - qed - thus ?case by blast -qed simp_all - -lemma minusinf_repeats: - assumes d: "d\ p d" and linp: "iszlfm p (a # bs)" - shows "Ifm ((real(x - k*d))#bs) (minusinf p) = Ifm (real x #bs) (minusinf p)" -using linp d -proof(induct p rule: iszlfm.induct) - case (9 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ - hence "\ k. d=i*k" by (simp add: dvd_def) - then obtain "di" where di_def: "d=i*di" by blast - show ?case - proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="real x - real k * real d" and b'="real x"] right_diff_distrib, rule iffI) - assume - "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" - (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt") - hence "\ (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def) - hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" - by (simp add: algebra_simps di_def) - hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))" - by (simp add: algebra_simps) - hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast - thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp - next - assume - "real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e") - hence "\ (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def) - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real d)" by simp - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real i * real di)" by (simp add: di_def) - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real (l - c*k*di))" by (simp add: algebra_simps) - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)" - by blast - thus "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" using rdvd_def by simp - qed -next - case (10 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ - hence "\ k. d=i*k" by (simp add: dvd_def) - then obtain "di" where di_def: "d=i*di" by blast - show ?case - proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="real x - real k * real d" and b'="real x"] right_diff_distrib, rule iffI) - assume - "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" - (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt") - hence "\ (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def) - hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" - by (simp add: algebra_simps di_def) - hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))" - by (simp add: algebra_simps) - hence "\ (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast - thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp - next - assume - "real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e") - hence "\ (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def) - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real d)" by simp - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l) - real c * (real k * real i * real di)" by (simp add: di_def) - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real (l - c*k*di))" by (simp add: algebra_simps) - hence "\ (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)" - by blast - thus "real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e" using rdvd_def by simp - qed -qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="real(x - k*d)" and b'="real x"] simp del: real_of_int_mult real_of_int_diff) - -lemma minusinf_ex: - assumes lin: "iszlfm p (real (a::int) #bs)" - and exmi: "\ (x::int). Ifm (real x#bs) (minusinf p)" (is "\ x. ?P1 x") - shows "\ (x::int). Ifm (real x#bs) p" (is "\ x. ?P x") -proof- - let ?d = "\ p" - from \ [OF lin] have dpos: "?d >0" by simp - from \ [OF lin] have alld: "d\ p ?d" by simp - from minusinf_repeats[OF alld lin] have th1:"\ x k. ?P1 x = ?P1 (x - (k * ?d))" by simp - from minusinf_inf[OF lin] have th2:"\ z. \ x. x (?P x = ?P1 x)" by blast - from minusinfinity [OF dpos th1 th2] exmi show ?thesis by blast -qed - -lemma minusinf_bex: - assumes lin: "iszlfm p (real (a::int) #bs)" - shows "(\ (x::int). Ifm (real x#bs) (minusinf p)) = - (\ (x::int)\ {1..\ p}. Ifm (real x#bs) (minusinf p))" - (is "(\ x. ?P x) = _") -proof- - let ?d = "\ p" - from \ [OF lin] have dpos: "?d >0" by simp - from \ [OF lin] have alld: "d\ p ?d" by simp - from minusinf_repeats[OF alld lin] have th1:"\ x k. ?P x = ?P (x - (k * ?d))" by simp - from periodic_finite_ex[OF dpos th1] show ?thesis by blast -qed - -lemma dvd1_eq1: "x >0 \ (x::int) dvd 1 = (x = 1)" by auto - -consts - a\ :: "fm \ int \ fm" (* adjusts the coeffitients of a formula *) - d\ :: "fm \ int \ bool" (* tests if all coeffs c of c divide a given l*) - \ :: "fm \ int" (* computes the lcm of all coefficients of x*) - \ :: "fm \ num list" - \ :: "fm \ num list" - -recdef a\ "measure size" - "a\ (And p q) = (\ k. And (a\ p k) (a\ q k))" - "a\ (Or p q) = (\ k. Or (a\ p k) (a\ q k))" - "a\ (Eq (CN 0 c e)) = (\ k. Eq (CN 0 1 (Mul (k div c) e)))" - "a\ (NEq (CN 0 c e)) = (\ k. NEq (CN 0 1 (Mul (k div c) e)))" - "a\ (Lt (CN 0 c e)) = (\ k. Lt (CN 0 1 (Mul (k div c) e)))" - "a\ (Le (CN 0 c e)) = (\ k. Le (CN 0 1 (Mul (k div c) e)))" - "a\ (Gt (CN 0 c e)) = (\ k. Gt (CN 0 1 (Mul (k div c) e)))" - "a\ (Ge (CN 0 c e)) = (\ k. Ge (CN 0 1 (Mul (k div c) e)))" - "a\ (Dvd i (CN 0 c e)) =(\ k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" - "a\ (NDvd i (CN 0 c e))=(\ k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" - "a\ p = (\ k. p)" - -recdef d\ "measure size" - "d\ (And p q) = (\ k. (d\ p k) \ (d\ q k))" - "d\ (Or p q) = (\ k. (d\ p k) \ (d\ q k))" - "d\ (Eq (CN 0 c e)) = (\ k. c dvd k)" - "d\ (NEq (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Lt (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Le (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Gt (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Ge (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Dvd i (CN 0 c e)) =(\ k. c dvd k)" - "d\ (NDvd i (CN 0 c e))=(\ k. c dvd k)" - "d\ p = (\ k. True)" - -recdef \ "measure size" - "\ (And p q) = zlcm (\ p) (\ q)" - "\ (Or p q) = zlcm (\ p) (\ q)" - "\ (Eq (CN 0 c e)) = c" - "\ (NEq (CN 0 c e)) = c" - "\ (Lt (CN 0 c e)) = c" - "\ (Le (CN 0 c e)) = c" - "\ (Gt (CN 0 c e)) = c" - "\ (Ge (CN 0 c e)) = c" - "\ (Dvd i (CN 0 c e)) = c" - "\ (NDvd i (CN 0 c e))= c" - "\ p = 1" - -recdef \ "measure size" - "\ (And p q) = (\ p @ \ q)" - "\ (Or p q) = (\ p @ \ q)" - "\ (Eq (CN 0 c e)) = [Sub (C -1) e]" - "\ (NEq (CN 0 c e)) = [Neg e]" - "\ (Lt (CN 0 c e)) = []" - "\ (Le (CN 0 c e)) = []" - "\ (Gt (CN 0 c e)) = [Neg e]" - "\ (Ge (CN 0 c e)) = [Sub (C -1) e]" - "\ p = []" - -recdef \ "measure size" - "\ (And p q) = (\ p @ \ q)" - "\ (Or p q) = (\ p @ \ q)" - "\ (Eq (CN 0 c e)) = [Add (C -1) e]" - "\ (NEq (CN 0 c e)) = [e]" - "\ (Lt (CN 0 c e)) = [e]" - "\ (Le (CN 0 c e)) = [Add (C -1) e]" - "\ (Gt (CN 0 c e)) = []" - "\ (Ge (CN 0 c e)) = []" - "\ p = []" -consts mirror :: "fm \ fm" -recdef mirror "measure size" - "mirror (And p q) = And (mirror p) (mirror q)" - "mirror (Or p q) = Or (mirror p) (mirror q)" - "mirror (Eq (CN 0 c e)) = Eq (CN 0 c (Neg e))" - "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))" - "mirror (Lt (CN 0 c e)) = Gt (CN 0 c (Neg e))" - "mirror (Le (CN 0 c e)) = Ge (CN 0 c (Neg e))" - "mirror (Gt (CN 0 c e)) = Lt (CN 0 c (Neg e))" - "mirror (Ge (CN 0 c e)) = Le (CN 0 c (Neg e))" - "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))" - "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))" - "mirror p = p" - -lemma mirror\\: - assumes lp: "iszlfm p (a#bs)" - shows "(Inum (real (i::int)#bs)) ` set (\ p) = (Inum (real i#bs)) ` set (\ (mirror p))" -using lp -by (induct p rule: mirror.induct, auto) - -lemma mirror: - assumes lp: "iszlfm p (a#bs)" - shows "Ifm (real (x::int)#bs) (mirror p) = Ifm (real (- x)#bs) p" -using lp -proof(induct p rule: iszlfm.induct) - case (9 j c e) - have th: "(real j rdvd real c * real x - Inum (real x # bs) e) = - (real j rdvd - (real c * real x - Inum (real x # bs) e))" - by (simp only: rdvd_minus[symmetric]) - from prems th show ?case - by (simp add: algebra_simps - numbound0_I[where bs="bs" and b'="real x" and b="- real x"]) -next - case (10 j c e) - have th: "(real j rdvd real c * real x - Inum (real x # bs) e) = - (real j rdvd - (real c * real x - Inum (real x # bs) e))" - by (simp only: rdvd_minus[symmetric]) - from prems th show ?case - by (simp add: algebra_simps - numbound0_I[where bs="bs" and b'="real x" and b="- real x"]) -qed (auto simp add: numbound0_I[where bs="bs" and b="real x" and b'="- real x"] nth_pos2) - -lemma mirror_l: "iszlfm p (a#bs) \ iszlfm (mirror p) (a#bs)" -by (induct p rule: mirror.induct, auto simp add: isint_neg) - -lemma mirror_d\: "iszlfm p (a#bs) \ d\ p 1 - \ iszlfm (mirror p) (a#bs) \ d\ (mirror p) 1" -by (induct p rule: mirror.induct, auto simp add: isint_neg) - -lemma mirror_\: "iszlfm p (a#bs) \ \ (mirror p) = \ p" -by (induct p rule: mirror.induct,auto) - - -lemma mirror_ex: - assumes lp: "iszlfm p (real (i::int)#bs)" - shows "(\ (x::int). Ifm (real x#bs) (mirror p)) = (\ (x::int). Ifm (real x#bs) p)" - (is "(\ x. ?I x ?mp) = (\ x. ?I x p)") -proof(auto) - fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast - thus "\ x. ?I x p" by blast -next - fix x assume "?I x p" hence "?I (- x) ?mp" - using mirror[OF lp, where x="- x", symmetric] by auto - thus "\ x. ?I x ?mp" by blast -qed - -lemma \_numbound0: assumes lp: "iszlfm p bs" - shows "\ b\ set (\ p). numbound0 b" - using lp by (induct p rule: \.induct,auto) - -lemma d\_mono: - assumes linp: "iszlfm p (a #bs)" - and dr: "d\ p l" - and d: "l dvd l'" - shows "d\ p l'" -using dr linp zdvd_trans[where n="l" and k="l'", simplified d] -by (induct p rule: iszlfm.induct) simp_all - -lemma \_l: assumes lp: "iszlfm p (a#bs)" - shows "\ b\ set (\ p). numbound0 b \ isint b (a#bs)" -using lp -by(induct p rule: \.induct, auto simp add: isint_add isint_c) - -lemma \: - assumes linp: "iszlfm p (a #bs)" - shows "\ p > 0 \ d\ p (\ p)" -using linp -proof(induct p rule: iszlfm.induct) - case (1 p q) - from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp - from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp - from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] - d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] - dl1 dl2 show ?case by (auto simp add: zlcm_pos) -next - case (2 p q) - from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp - from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp - from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] - d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] - dl1 dl2 show ?case by (auto simp add: zlcm_pos) -qed (auto simp add: zlcm_pos) - -lemma a\: assumes linp: "iszlfm p (a #bs)" and d: "d\ p l" and lp: "l > 0" - shows "iszlfm (a\ p l) (a #bs) \ d\ (a\ p l) 1 \ (Ifm (real (l * x) #bs) (a\ p l) = Ifm ((real x)#bs) p)" -using linp d -proof (induct p rule: iszlfm.induct) - case (5 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(real l * real x + real (l div c) * Inum (real x # bs) e < (0\real)) = - (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e < 0)" - by simp - also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) < (real (l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (real c * real x + Inum (real x # bs) e < 0)" - using mult_less_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp -next - case (6 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(real l * real x + real (l div c) * Inum (real x # bs) e \ (0\real)) = - (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \ 0)" - by simp - also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) \ (real (l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (real c * real x + Inum (real x # bs) e \ 0)" - using mult_le_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp -next - case (7 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(real l * real x + real (l div c) * Inum (real x # bs) e > (0\real)) = - (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e > 0)" - by simp - also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) > (real (l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (real c * real x + Inum (real x # bs) e > 0)" - using zero_less_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp -next - case (8 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(real l * real x + real (l div c) * Inum (real x # bs) e \ (0\real)) = - (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \ 0)" - by simp - also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) \ (real (l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (real c * real x + Inum (real x # bs) e \ 0)" - using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp -next - case (3 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(real l * real x + real (l div c) * Inum (real x # bs) e = (0\real)) = - (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = 0)" - by simp - also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) = (real (l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (real c * real x + Inum (real x # bs) e = 0)" - using mult_eq_0_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp -next - case (4 c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(real l * real x + real (l div c) * Inum (real x # bs) e \ (0\real)) = - (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \ 0)" - by simp - also have "\ = (real (l div c) * (real c * real x + Inum (real x # bs) e) \ (real (l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (real c * real x + Inum (real x # bs) e \ 0)" - using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] be isint_Mul[OF ei] by simp -next - case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and jp: "j > 0" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(\ (k::int). real l * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k) = (\ (k::int). real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k)" by simp - also have "\ = (\ (k::int). real (l div c) * (real c * real x + Inum (real x # bs) e - real j * real k) = real (l div c)*0)" by (simp add: algebra_simps) - also fix k have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)" - using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e - real j * real k"] ldcp by simp - also have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] rdvd_def be isint_Mul[OF ei] mult_strict_mono[OF ldcp jp ldcp ] by simp -next - case (10 j c e) hence cp: "c>0" and be: "numbound0 e" and ei:"isint e (a#bs)" and jp: "j > 0" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(\ (k::int). real l * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k) = (\ (k::int). real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = (real (l div c) * real j) * real k)" by simp - also have "\ = (\ (k::int). real (l div c) * (real c * real x + Inum (real x # bs) e - real j * real k) = real (l div c)*0)" by (simp add: algebra_simps) - also fix k have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)" - using zero_le_mult_iff [where a="real (l div c)" and b="real c * real x + Inum (real x # bs) e - real j * real k"] ldcp by simp - also have "\ = (\ (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp - finally show ?case using numbound0_I[OF be,where b="real (l * x)" and b'="real x" and bs="bs"] rdvd_def be isint_Mul[OF ei] mult_strict_mono[OF ldcp jp ldcp ] by simp -qed (simp_all add: nth_pos2 numbound0_I[where bs="bs" and b="real (l * x)" and b'="real x"] isint_Mul del: real_of_int_mult) - -lemma a\_ex: assumes linp: "iszlfm p (a#bs)" and d: "d\ p l" and lp: "l>0" - shows "(\ x. l dvd x \ Ifm (real x #bs) (a\ p l)) = (\ (x::int). Ifm (real x#bs) p)" - (is "(\ x. l dvd x \ ?P x) = (\ x. ?P' x)") -proof- - have "(\ x. l dvd x \ ?P x) = (\ (x::int). ?P (l*x))" - using unity_coeff_ex[where l="l" and P="?P", simplified] by simp - also have "\ = (\ (x::int). ?P' x)" using a\[OF linp d lp] by simp - finally show ?thesis . -qed - -lemma \: - assumes lp: "iszlfm p (a#bs)" - and u: "d\ p 1" - and d: "d\ p d" - and dp: "d > 0" - and nob: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). real x = b + real j)" - and p: "Ifm (real x#bs) p" (is "?P x") - shows "?P (x - d)" -using lp u d dp nob p -proof(induct p rule: iszlfm.induct) - case (5 c e) hence c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ - with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems - show ?case by (simp del: real_of_int_minus) -next - case (6 c e) hence c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ - with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems - show ?case by (simp del: real_of_int_minus) -next - case (7 c e) hence p: "Ifm (real x #bs) (Gt (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" and ie1:"isint e (a#bs)" using dvd1_eq1[where x="c"] by simp+ - let ?e = "Inum (real x # bs) e" - from ie1 have ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="a#bs"] - numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"] - by (simp add: isint_iff) - {assume "real (x-d) +?e > 0" hence ?case using c1 - numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] - by (simp del: real_of_int_minus)} - moreover - {assume H: "\ real (x-d) + ?e > 0" - let ?v="Neg e" - have vb: "?v \ set (\ (Gt (CN 0 c e)))" by simp - from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]] - have nob: "\ (\ j\ {1 ..d}. real x = - ?e + real j)" by auto - from H p have "real x + ?e > 0 \ real x + ?e \ real d" by (simp add: c1) - hence "real (x + floor ?e) > real (0::int) \ real (x + floor ?e) \ real d" - using ie by simp - hence "x + floor ?e \ 1 \ x + floor ?e \ d" by simp - hence "\ (j::int) \ {1 .. d}. j = x + floor ?e" by simp - hence "\ (j::int) \ {1 .. d}. real x = real (- floor ?e + j)" - by (simp only: real_of_int_inject) (simp add: algebra_simps) - hence "\ (j::int) \ {1 .. d}. real x = - ?e + real j" - by (simp add: ie[simplified isint_iff]) - with nob have ?case by auto} - ultimately show ?case by blast -next - case (8 c e) hence p: "Ifm (real x #bs) (Ge (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" - and ie1:"isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+ - let ?e = "Inum (real x # bs) e" - from ie1 have ie: "real (floor ?e) = ?e" using numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real x)#bs"] - by (simp add: isint_iff) - {assume "real (x-d) +?e \ 0" hence ?case using c1 - numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] - by (simp del: real_of_int_minus)} - moreover - {assume H: "\ real (x-d) + ?e \ 0" - let ?v="Sub (C -1) e" - have vb: "?v \ set (\ (Ge (CN 0 c e)))" by simp - from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]] - have nob: "\ (\ j\ {1 ..d}. real x = - ?e - 1 + real j)" by auto - from H p have "real x + ?e \ 0 \ real x + ?e < real d" by (simp add: c1) - hence "real (x + floor ?e) \ real (0::int) \ real (x + floor ?e) < real d" - using ie by simp - hence "x + floor ?e +1 \ 1 \ x + floor ?e + 1 \ d" by simp - hence "\ (j::int) \ {1 .. d}. j = x + floor ?e + 1" by simp - hence "\ (j::int) \ {1 .. d}. x= - floor ?e - 1 + j" by (simp add: algebra_simps) - hence "\ (j::int) \ {1 .. d}. real x= real (- floor ?e - 1 + j)" - by (simp only: real_of_int_inject) - hence "\ (j::int) \ {1 .. d}. real x= - ?e - 1 + real j" - by (simp add: ie[simplified isint_iff]) - with nob have ?case by simp } - ultimately show ?case by blast -next - case (3 c e) hence p: "Ifm (real x #bs) (Eq (CN 0 c e))" (is "?p x") and c1: "c=1" - and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+ - let ?e = "Inum (real x # bs) e" - let ?v="(Sub (C -1) e)" - have vb: "?v \ set (\ (Eq (CN 0 c e)))" by simp - from p have "real x= - ?e" by (simp add: c1) with prems(11) show ?case using dp - by simp (erule ballE[where x="1"], - simp_all add:algebra_simps numbound0_I[OF bn,where b="real x"and b'="a"and bs="bs"]) -next - case (4 c e)hence p: "Ifm (real x #bs) (NEq (CN 0 c e))" (is "?p x") and c1: "c=1" - and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+ - let ?e = "Inum (real x # bs) e" - let ?v="Neg e" - have vb: "?v \ set (\ (NEq (CN 0 c e)))" by simp - {assume "real x - real d + Inum ((real (x -d)) # bs) e \ 0" - hence ?case by (simp add: c1)} - moreover - {assume H: "real x - real d + Inum ((real (x -d)) # bs) e = 0" - hence "real x = - Inum ((real (x -d)) # bs) e + real d" by simp - hence "real x = - Inum (a # bs) e + real d" - by (simp add: numbound0_I[OF bn,where b="real x - real d"and b'="a"and bs="bs"]) - with prems(11) have ?case using dp by simp} - ultimately show ?case by blast -next - case (9 j c e) hence p: "Ifm (real x #bs) (Dvd j (CN 0 c e))" (is "?p x") and c1: "c=1" - and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ - let ?e = "Inum (real x # bs) e" - from prems have "isint e (a #bs)" by simp - hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real x)#bs"] numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] - by (simp add: isint_iff) - from prems have id: "j dvd d" by simp - from c1 ie[symmetric] have "?p x = (real j rdvd real (x+ floor ?e))" by simp - also have "\ = (j dvd x + floor ?e)" - using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp - also have "\ = (j dvd x - d + floor ?e)" - using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp - also have "\ = (real j rdvd real (x - d + floor ?e))" - using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified] - ie by simp - also have "\ = (real j rdvd real x - real d + ?e)" - using ie by simp - finally show ?case - using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp -next - case (10 j c e) hence p: "Ifm (real x #bs) (NDvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+ - let ?e = "Inum (real x # bs) e" - from prems have "isint e (a#bs)" by simp - hence ie: "real (floor ?e) = ?e" using numbound0_I[OF bn,where b="real x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real x)#bs"] - by (simp add: isint_iff) - from prems have id: "j dvd d" by simp - from c1 ie[symmetric] have "?p x = (\ real j rdvd real (x+ floor ?e))" by simp - also have "\ = (\ j dvd x + floor ?e)" - using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp - also have "\ = (\ j dvd x - d + floor ?e)" - using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp - also have "\ = (\ real j rdvd real (x - d + floor ?e))" - using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified] - ie by simp - also have "\ = (\ real j rdvd real x - real d + ?e)" - using ie by simp - finally show ?case using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp -qed (auto simp add: numbound0_I[where bs="bs" and b="real (x - d)" and b'="real x"] nth_pos2 simp del: real_of_int_diff) - -lemma \': - assumes lp: "iszlfm p (a #bs)" - and u: "d\ p 1" - and d: "d\ p d" - and dp: "d > 0" - shows "\ x. \(\(j::int) \ {1 .. d}. \ b\ set(\ p). Ifm ((Inum (a#bs) b + real j) #bs) p) \ Ifm (real x#bs) p \ Ifm (real (x - d)#bs) p" (is "\ x. ?b \ ?P x \ ?P (x - d)") -proof(clarify) - fix x - assume nb:"?b" and px: "?P x" - hence nb2: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). real x = b + real j)" - by auto - from \[OF lp u d dp nb2 px] show "?P (x -d )" . -qed - -lemma \_int: assumes lp: "iszlfm p bs" - shows "\ b\ set (\ p). isint b bs" -using lp by (induct p rule: iszlfm.induct) (auto simp add: isint_neg isint_sub) - -lemma cpmi_eq: "0 < D \ (EX z::int. ALL x. x < z --> (P x = P1 x)) -==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) -==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D)))) -==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))" -apply(rule iffI) -prefer 2 -apply(drule minusinfinity) -apply assumption+ -apply(fastsimp) -apply clarsimp -apply(subgoal_tac "!!k. 0<=k \ !x. P x \ P (x - k*D)") -apply(frule_tac x = x and z=z in decr_lemma) -apply(subgoal_tac "P1(x - (\x - z\ + 1) * D)") -prefer 2 -apply(subgoal_tac "0 <= (\x - z\ + 1)") -prefer 2 apply arith - apply fastsimp -apply(drule (1) periodic_finite_ex) -apply blast -apply(blast dest:decr_mult_lemma) -done - - -theorem cp_thm: - assumes lp: "iszlfm p (a #bs)" - and u: "d\ p 1" - and d: "d\ p d" - and dp: "d > 0" - shows "(\ (x::int). Ifm (real x #bs) p) = (\ j\ {1.. d}. Ifm (real j #bs) (minusinf p) \ (\ b \ set (\ p). Ifm ((Inum (a#bs) b + real j) #bs) p))" - (is "(\ (x::int). ?P (real x)) = (\ j\ ?D. ?M j \ (\ b\ ?B. ?P (?I b + real j)))") -proof- - from minusinf_inf[OF lp] - have th: "\(z::int). \x_int[OF lp] isint_iff[where bs="a # bs"] have B: "\ b\ ?B. real (floor (?I b)) = ?I b" by simp - from B[rule_format] - have "(\j\?D. \b\ ?B. ?P (?I b + real j)) = (\j\?D. \b\ ?B. ?P (real (floor (?I b)) + real j))" - by simp - also have "\ = (\j\?D. \b\ ?B. ?P (real (floor (?I b) + j)))" by simp - also have"\ = (\ j \ ?D. \ b \ ?B'. ?P (real (b + j)))" by blast - finally have BB': - "(\j\?D. \b\ ?B. ?P (?I b + real j)) = (\ j \ ?D. \ b \ ?B'. ?P (real (b + j)))" - by blast - hence th2: "\ x. \ (\ j \ ?D. \ b \ ?B'. ?P (real (b + j))) \ ?P (real x) \ ?P (real (x - d))" using \'[OF lp u d dp] by blast - from minusinf_repeats[OF d lp] - have th3: "\ x k. ?M x = ?M (x-k*d)" by simp - from cpmi_eq[OF dp th th2 th3] BB' show ?thesis by blast -qed - - (* Reddy and Loveland *) - - -consts - \ :: "fm \ (num \ int) list" (* Compute the Reddy and Loveland Bset*) - \\:: "fm \ num \ int \ fm" (* Performs the modified substitution of Reddy and Loveland*) - \\ :: "fm \ (num\int) list" - a\ :: "fm \ int \ fm" -recdef \ "measure size" - "\ (And p q) = (\ p @ \ q)" - "\ (Or p q) = (\ p @ \ q)" - "\ (Eq (CN 0 c e)) = [(Sub (C -1) e,c)]" - "\ (NEq (CN 0 c e)) = [(Neg e,c)]" - "\ (Lt (CN 0 c e)) = []" - "\ (Le (CN 0 c e)) = []" - "\ (Gt (CN 0 c e)) = [(Neg e, c)]" - "\ (Ge (CN 0 c e)) = [(Sub (C (-1)) e, c)]" - "\ p = []" - -recdef \\ "measure size" - "\\ (And p q) = (\ (t,k). And (\\ p (t,k)) (\\ q (t,k)))" - "\\ (Or p q) = (\ (t,k). Or (\\ p (t,k)) (\\ q (t,k)))" - "\\ (Eq (CN 0 c e)) = (\ (t,k). if k dvd c then (Eq (Add (Mul (c div k) t) e)) - else (Eq (Add (Mul c t) (Mul k e))))" - "\\ (NEq (CN 0 c e)) = (\ (t,k). if k dvd c then (NEq (Add (Mul (c div k) t) e)) - else (NEq (Add (Mul c t) (Mul k e))))" - "\\ (Lt (CN 0 c e)) = (\ (t,k). if k dvd c then (Lt (Add (Mul (c div k) t) e)) - else (Lt (Add (Mul c t) (Mul k e))))" - "\\ (Le (CN 0 c e)) = (\ (t,k). if k dvd c then (Le (Add (Mul (c div k) t) e)) - else (Le (Add (Mul c t) (Mul k e))))" - "\\ (Gt (CN 0 c e)) = (\ (t,k). if k dvd c then (Gt (Add (Mul (c div k) t) e)) - else (Gt (Add (Mul c t) (Mul k e))))" - "\\ (Ge (CN 0 c e)) = (\ (t,k). if k dvd c then (Ge (Add (Mul (c div k) t) e)) - else (Ge (Add (Mul c t) (Mul k e))))" - "\\ (Dvd i (CN 0 c e)) =(\ (t,k). if k dvd c then (Dvd i (Add (Mul (c div k) t) e)) - else (Dvd (i*k) (Add (Mul c t) (Mul k e))))" - "\\ (NDvd i (CN 0 c e))=(\ (t,k). if k dvd c then (NDvd i (Add (Mul (c div k) t) e)) - else (NDvd (i*k) (Add (Mul c t) (Mul k e))))" - "\\ p = (\ (t,k). p)" - -recdef \\ "measure size" - "\\ (And p q) = (\\ p @ \\ q)" - "\\ (Or p q) = (\\ p @ \\ q)" - "\\ (Eq (CN 0 c e)) = [(Add (C -1) e,c)]" - "\\ (NEq (CN 0 c e)) = [(e,c)]" - "\\ (Lt (CN 0 c e)) = [(e,c)]" - "\\ (Le (CN 0 c e)) = [(Add (C -1) e,c)]" - "\\ p = []" - - (* Simulates normal substituion by modifying the formula see correctness theorem *) - -recdef a\ "measure size" - "a\ (And p q) = (\ k. And (a\ p k) (a\ q k))" - "a\ (Or p q) = (\ k. Or (a\ p k) (a\ q k))" - "a\ (Eq (CN 0 c e)) = (\ k. if k dvd c then (Eq (CN 0 (c div k) e)) - else (Eq (CN 0 c (Mul k e))))" - "a\ (NEq (CN 0 c e)) = (\ k. if k dvd c then (NEq (CN 0 (c div k) e)) - else (NEq (CN 0 c (Mul k e))))" - "a\ (Lt (CN 0 c e)) = (\ k. if k dvd c then (Lt (CN 0 (c div k) e)) - else (Lt (CN 0 c (Mul k e))))" - "a\ (Le (CN 0 c e)) = (\ k. if k dvd c then (Le (CN 0 (c div k) e)) - else (Le (CN 0 c (Mul k e))))" - "a\ (Gt (CN 0 c e)) = (\ k. if k dvd c then (Gt (CN 0 (c div k) e)) - else (Gt (CN 0 c (Mul k e))))" - "a\ (Ge (CN 0 c e)) = (\ k. if k dvd c then (Ge (CN 0 (c div k) e)) - else (Ge (CN 0 c (Mul k e))))" - "a\ (Dvd i (CN 0 c e)) = (\ k. if k dvd c then (Dvd i (CN 0 (c div k) e)) - else (Dvd (i*k) (CN 0 c (Mul k e))))" - "a\ (NDvd i (CN 0 c e)) = (\ k. if k dvd c then (NDvd i (CN 0 (c div k) e)) - else (NDvd (i*k) (CN 0 c (Mul k e))))" - "a\ p = (\ k. p)" - -constdefs \ :: "fm \ int \ num \ fm" - "\ p k t \ And (Dvd k t) (\\ p (t,k))" - -lemma \\: - assumes linp: "iszlfm p (real (x::int)#bs)" - and kpos: "real k > 0" - and tnb: "numbound0 t" - and tint: "isint t (real x#bs)" - and kdt: "k dvd floor (Inum (b'#bs) t)" - shows "Ifm (real x#bs) (\\ p (t,k)) = - (Ifm ((real ((floor (Inum (b'#bs) t)) div k))#bs) p)" - (is "?I (real x) (?s p) = (?I (real ((floor (?N b' t)) div k)) p)" is "_ = (?I ?tk p)") -using linp kpos tnb -proof(induct p rule: \\.induct) - case (3 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (Eq (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k = 0)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (Eq (CN 0 c e)))" using nonzero_eq_divide_eq[OF knz', where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (4 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (NEq (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \ 0)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (NEq (CN 0 c e)))" using nonzero_eq_divide_eq[OF knz', where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (5 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (Lt (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k < 0)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (Lt (CN 0 c e)))" using pos_less_divide_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (6 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (Le (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \ 0)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (Le (CN 0 c e)))" using pos_le_divide_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (7 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (Gt (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k > 0)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (Gt (CN 0 c e)))" using pos_divide_less_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (8 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (Ge (CN 0 c e))) = ((real c * (?N (real x) t / real k) + ?N (real x) e)* real k \ 0)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (Ge (CN 0 c e)))" using pos_divide_le_eq[OF kpos, where a="real c * (?N (real x) t / real k) + ?N (real x) e" and b="0", symmetric] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (9 i c e) from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (Dvd i (CN 0 c e))) = (real i * real k rdvd (real c * (?N (real x) t / real k) + ?N (real x) e)* real k)" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (Dvd i (CN 0 c e)))" using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -next - case (10 i c e) from prems have cp: "c > 0" and nb: "numbound0 e" by auto - {assume kdc: "k dvd c" - from kpos have knz: "k\0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } - moreover - {assume "\ k dvd c" - from kpos have knz: "k\0" by simp hence knz': "real k \ 0" by simp - from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp - from prems have "?I (real x) (?s (NDvd i (CN 0 c e))) = (\ (real i * real k rdvd (real c * (?N (real x) t / real k) + ?N (real x) e)* real k))" - using real_of_int_div[OF knz kdt] - numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti algebra_simps) - also have "\ = (?I ?tk (NDvd i (CN 0 c e)))" using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF knz kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"] - numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] - by (simp add: ti) - finally have ?case . } - ultimately show ?case by blast -qed (simp_all add: nth_pos2 bound0_I[where bs="bs" and b="real ((floor (?N b' t)) div k)" and b'="real x"] numbound0_I[where bs="bs" and b="real ((floor (?N b' t)) div k)" and b'="real x"]) - - -lemma a\: - assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "real k > 0" - shows "Ifm (real (x*k)#bs) (a\ p k) = Ifm (real x#bs) p" (is "?I (x*k) (?f p k) = ?I x p") -using lp bound0_I[where bs="bs" and b="real (x*k)" and b'="real x"] numbound0_I[where bs="bs" and b="real (x*k)" and b'="real x"] -proof(induct p rule: a\.induct) - case (3 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] nonzero_eq_divide_eq[OF knz', where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} - ultimately show ?case by blast -next - case (4 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] nonzero_eq_divide_eq[OF knz', where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} - ultimately show ?case by blast -next - case (5 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_less_divide_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} - ultimately show ?case by blast -next - case (6 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_le_divide_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} - ultimately show ?case by blast -next - case (7 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_divide_less_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} - ultimately show ?case by blast -next - case (8 c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume nkdc: "\ k dvd c" hence ?case using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] pos_divide_le_eq[OF kp, where b="0" and a="real c * real x + Inum (real x # bs) e", symmetric] by (simp add: algebra_simps)} - ultimately show ?case by blast -next - case (9 i c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume "\ k dvd c" - hence "Ifm (real (x*k)#bs) (a\ (Dvd i (CN 0 c e)) k) = - (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k)" - using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] - by (simp add: algebra_simps) - also have "\ = (Ifm (real x#bs) (Dvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"]) - finally have ?case . } - ultimately show ?case by blast -next - case (10 i c e) - from prems have cp: "c > 0" and nb: "numbound0 e" by auto - from kp have knz: "k\0" by simp hence knz': "real k \ 0" by simp - {assume kdc: "k dvd c" from prems have ?case using real_of_int_div[OF knz kdc] by simp } - moreover - {assume "\ k dvd c" - hence "Ifm (real (x*k)#bs) (a\ (NDvd i (CN 0 c e)) k) = - (\ (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k))" - using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] - by (simp add: algebra_simps) - also have "\ = (Ifm (real x#bs) (NDvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"]) - finally have ?case . } - ultimately show ?case by blast -qed (simp_all add: nth_pos2) - -lemma a\_ex: - assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0" - shows "(\ (x::int). real k rdvd real x \ Ifm (real x#bs) (a\ p k)) = - (\ (x::int). Ifm (real x#bs) p)" (is "(\ x. ?D x \ ?P' x) = (\ x. ?P x)") -proof- - have "(\ x. ?D x \ ?P' x) = (\ x. k dvd x \ ?P' x)" using int_rdvd_iff by simp - also have "\ = (\x. ?P' (x*k))" using unity_coeff_ex[where P="?P'" and l="k", simplified] - by (simp add: algebra_simps) - also have "\ = (\ x. ?P x)" using a\ iszlfm_gen[OF lp] kp by auto - finally show ?thesis . -qed - -lemma \\': assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0" and nb: "numbound0 t" - shows "Ifm (real x#bs) (\\ p (t,k)) = Ifm ((Inum (real x#bs) t)#bs) (a\ p k)" -using lp -by(induct p rule: \\.induct, simp_all add: - numbound0_I[OF nb, where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] - numbound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] - bound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] nth_pos2 cong: imp_cong) - -lemma \\_nb: assumes lp:"iszlfm p (a#bs)" and nb: "numbound0 t" - shows "bound0 (\\ p (t,k))" - using lp - by (induct p rule: iszlfm.induct, auto simp add: nb) - -lemma \_l: - assumes lp: "iszlfm p (real (i::int)#bs)" - shows "\ (b,k) \ set (\ p). k >0 \ numbound0 b \ isint b (real i#bs)" -using lp by (induct p rule: \.induct, auto simp add: isint_sub isint_neg) - -lemma \\_l: - assumes lp: "iszlfm p (real (i::int)#bs)" - shows "\ (b,k) \ set (\\ p). k >0 \ numbound0 b \ isint b (real i#bs)" -using lp isint_add [OF isint_c[where j="- 1"],where bs="real i#bs"] - by (induct p rule: \\.induct, auto) - -lemma zminusinf_\: - assumes lp: "iszlfm p (real (i::int)#bs)" - and nmi: "\ (Ifm (real i#bs) (minusinf p))" (is "\ (Ifm (real i#bs) (?M p))") - and ex: "Ifm (real i#bs) p" (is "?I i p") - shows "\ (e,c) \ set (\ p). real (c*i) > Inum (real i#bs) e" (is "\ (e,c) \ ?R p. real (c*i) > ?N i e") - using lp nmi ex -by (induct p rule: minusinf.induct, auto) - - -lemma \_And: "Ifm bs (\ (And p q) k t) = Ifm bs (And (\ p k t) (\ q k t))" -using \_def by auto -lemma \_Or: "Ifm bs (\ (Or p q) k t) = Ifm bs (Or (\ p k t) (\ q k t))" -using \_def by auto - -lemma \: assumes lp: "iszlfm p (real (i::int) #bs)" - and pi: "Ifm (real i#bs) p" - and d: "d\ p d" - and dp: "d > 0" - and nob: "\(e,c) \ set (\ p). \ j\ {1 .. c*d}. real (c*i) \ Inum (real i#bs) e + real j" - (is "\(e,c) \ set (\ p). \ j\ {1 .. c*d}. _ \ ?N i e + _") - shows "Ifm (real(i - d)#bs) p" - using lp pi d nob -proof(induct p rule: iszlfm.induct) - case (3 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" - and pi: "real (c*i) = - 1 - ?N i e + real (1::int)" and nob: "\ j\ {1 .. c*d}. real (c*i) \ -1 - ?N i e + real j" - by simp+ - from mult_strict_left_mono[OF dp cp] have one:"1 \ {1 .. c*d}" by auto - from nob[rule_format, where j="1", OF one] pi show ?case by simp -next - case (4 c e) - hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" - and nob: "\ j\ {1 .. c*d}. real (c*i) \ - ?N i e + real j" - by simp+ - {assume "real (c*i) \ - ?N i e + real (c*d)" - with numbound0_I[OF nb, where bs="bs" and b="real i - real d" and b'="real i"] - have ?case by (simp add: algebra_simps)} - moreover - {assume pi: "real (c*i) = - ?N i e + real (c*d)" - from mult_strict_left_mono[OF dp cp] have d: "(c*d) \ {1 .. c*d}" by simp - from nob[rule_format, where j="c*d", OF d] pi have ?case by simp } - ultimately show ?case by blast -next - case (5 c e) hence cp: "c > 0" by simp - from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] - real_of_int_mult] - show ?case using prems dp - by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] - algebra_simps) -next - case (6 c e) hence cp: "c > 0" by simp - from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] - real_of_int_mult] - show ?case using prems dp - by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] - algebra_simps) -next - case (7 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" - and nob: "\ j\ {1 .. c*d}. real (c*i) \ - ?N i e + real j" - and pi: "real (c*i) + ?N i e > 0" and cp': "real c >0" - by simp+ - let ?fe = "floor (?N i e)" - from pi cp have th:"(real i +?N i e / real c)*real c > 0" by (simp add: algebra_simps) - from pi ei[simplified isint_iff] have "real (c*i + ?fe) > real (0::int)" by simp - hence pi': "c*i + ?fe > 0" by (simp only: real_of_int_less_iff[symmetric]) - have "real (c*i) + ?N i e > real (c*d) \ real (c*i) + ?N i e \ real (c*d)" by auto - moreover - {assume "real (c*i) + ?N i e > real (c*d)" hence ?case - by (simp add: algebra_simps - numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} - moreover - {assume H:"real (c*i) + ?N i e \ real (c*d)" - with ei[simplified isint_iff] have "real (c*i + ?fe) \ real (c*d)" by simp - hence pid: "c*i + ?fe \ c*d" by (simp only: real_of_int_le_iff) - with pi' have "\ j1\ {1 .. c*d}. c*i + ?fe = j1" by auto - hence "\ j1\ {1 .. c*d}. real (c*i) = - ?N i e + real j1" - by (simp only: diff_def[symmetric] real_of_int_mult real_of_int_add real_of_int_inject[symmetric] ei[simplified isint_iff] algebra_simps) - with nob have ?case by blast } - ultimately show ?case by blast -next - case (8 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)" - and nob: "\ j\ {1 .. c*d}. real (c*i) \ - 1 - ?N i e + real j" - and pi: "real (c*i) + ?N i e \ 0" and cp': "real c >0" - by simp+ - let ?fe = "floor (?N i e)" - from pi cp have th:"(real i +?N i e / real c)*real c \ 0" by (simp add: algebra_simps) - from pi ei[simplified isint_iff] have "real (c*i + ?fe) \ real (0::int)" by simp - hence pi': "c*i + 1 + ?fe \ 1" by (simp only: real_of_int_le_iff[symmetric]) - have "real (c*i) + ?N i e \ real (c*d) \ real (c*i) + ?N i e < real (c*d)" by auto - moreover - {assume "real (c*i) + ?N i e \ real (c*d)" hence ?case - by (simp add: algebra_simps - numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} - moreover - {assume H:"real (c*i) + ?N i e < real (c*d)" - with ei[simplified isint_iff] have "real (c*i + ?fe) < real (c*d)" by simp - hence pid: "c*i + 1 + ?fe \ c*d" by (simp only: real_of_int_le_iff) - with pi' have "\ j1\ {1 .. c*d}. c*i + 1+ ?fe = j1" by auto - hence "\ j1\ {1 .. c*d}. real (c*i) + 1= - ?N i e + real j1" - by (simp only: diff_def[symmetric] real_of_int_mult real_of_int_add real_of_int_inject[symmetric] ei[simplified isint_iff] algebra_simps real_of_one) - hence "\ j1\ {1 .. c*d}. real (c*i) = (- ?N i e + real j1) - 1" - by (simp only: algebra_simps diff_def[symmetric]) - hence "\ j1\ {1 .. c*d}. real (c*i) = - 1 - ?N i e + real j1" - by (simp only: add_ac diff_def) - with nob have ?case by blast } - ultimately show ?case by blast -next - case (9 j c e) hence p: "real j rdvd real (c*i) + ?N i e" (is "?p x") and cp: "c > 0" and bn:"numbound0 e" by simp+ - let ?e = "Inum (real i # bs) e" - from prems have "isint e (real i #bs)" by simp - hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real i)#bs"] numbound0_I[OF bn,where b="real i" and b'="real i" and bs="bs"] - by (simp add: isint_iff) - from prems have id: "j dvd d" by simp - from ie[symmetric] have "?p i = (real j rdvd real (c*i+ floor ?e))" by simp - also have "\ = (j dvd c*i + floor ?e)" - using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp - also have "\ = (j dvd c*i - c*d + floor ?e)" - using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp - also have "\ = (real j rdvd real (c*i - c*d + floor ?e))" - using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified] - ie by simp - also have "\ = (real j rdvd real (c*(i - d)) + ?e)" - using ie by (simp add:algebra_simps) - finally show ?case - using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p - by (simp add: algebra_simps) -next - case (10 j c e) hence p: "\ (real j rdvd real (c*i) + ?N i e)" (is "?p x") and cp: "c > 0" and bn:"numbound0 e" by simp+ - let ?e = "Inum (real i # bs) e" - from prems have "isint e (real i #bs)" by simp - hence ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="(real i)#bs"] numbound0_I[OF bn,where b="real i" and b'="real i" and bs="bs"] - by (simp add: isint_iff) - from prems have id: "j dvd d" by simp - from ie[symmetric] have "?p i = (\ (real j rdvd real (c*i+ floor ?e)))" by simp - also have "\ = Not (j dvd c*i + floor ?e)" - using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp - also have "\ = Not (j dvd c*i - c*d + floor ?e)" - using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp - also have "\ = Not (real j rdvd real (c*i - c*d + floor ?e))" - using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified] - ie by simp - also have "\ = Not (real j rdvd real (c*(i - d)) + ?e)" - using ie by (simp add:algebra_simps) - finally show ?case - using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p - by (simp add: algebra_simps) -qed(auto simp add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] nth_pos2) - -lemma \_nb: assumes lp: "iszlfm p (a#bs)" and nb: "numbound0 t" - shows "bound0 (\ p k t)" - using \\_nb[OF lp nb] nb by (simp add: \_def) - -lemma \': assumes lp: "iszlfm p (a #bs)" - and d: "d\ p d" - and dp: "d > 0" - shows "\ x. \(\ (e,c) \ set(\ p). \(j::int) \ {1 .. c*d}. Ifm (a #bs) (\ p c (Add e (C j)))) \ Ifm (real x#bs) p \ Ifm (real (x - d)#bs) p" (is "\ x. ?b x \ ?P x \ ?P (x - d)") -proof(clarify) - fix x - assume nob1:"?b x" and px: "?P x" - from iszlfm_gen[OF lp, rule_format, where y="real x"] have lp': "iszlfm p (real x#bs)". - have nob: "\(e, c)\set (\ p). \j\{1..c * d}. real (c * x) \ Inum (real x # bs) e + real j" - proof(clarify) - fix e c j assume ecR: "(e,c) \ set (\ p)" and jD: "j\ {1 .. c*d}" - and cx: "real (c*x) = Inum (real x#bs) e + real j" - let ?e = "Inum (real x#bs) e" - let ?fe = "floor ?e" - from \_l[OF lp'] ecR have ei:"isint e (real x#bs)" and cp:"c>0" and nb:"numbound0 e" - by auto - from numbound0_gen [OF nb ei, rule_format,where y="a"] have "isint e (a#bs)" . - from cx ei[simplified isint_iff] have "real (c*x) = real (?fe + j)" by simp - hence cx: "c*x = ?fe + j" by (simp only: real_of_int_inject) - hence cdej:"c dvd ?fe + j" by (simp add: dvd_def) (rule_tac x="x" in exI, simp) - hence "real c rdvd real (?fe + j)" by (simp only: int_rdvd_iff) - hence rcdej: "real c rdvd ?e + real j" by (simp add: ei[simplified isint_iff]) - from cx have "(c*x) div c = (?fe + j) div c" by simp - with cp have "x = (?fe + j) div c" by simp - with px have th: "?P ((?fe + j) div c)" by auto - from cp have cp': "real c > 0" by simp - from cdej have cdej': "c dvd floor (Inum (real x#bs) (Add e (C j)))" by simp - from nb have nb': "numbound0 (Add e (C j))" by simp - have ji: "isint (C j) (real x#bs)" by (simp add: isint_def) - from isint_add[OF ei ji] have ei':"isint (Add e (C j)) (real x#bs)" . - from th \\[where b'="real x", OF lp' cp' nb' ei' cdej',symmetric] - have "Ifm (real x#bs) (\\ p (Add e (C j), c))" by simp - with rcdej have th: "Ifm (real x#bs) (\ p c (Add e (C j)))" by (simp add: \_def) - from th bound0_I[OF \_nb[OF lp nb', where k="c"],where bs="bs" and b="real x" and b'="a"] - have "Ifm (a#bs) (\ p c (Add e (C j)))" by blast - with ecR jD nob1 show "False" by blast - qed - from \[OF lp' px d dp nob] show "?P (x -d )" . -qed - - -lemma rl_thm: - assumes lp: "iszlfm p (real (i::int)#bs)" - shows "(\ (x::int). Ifm (real x#bs) p) = ((\ j\ {1 .. \ p}. Ifm (real j#bs) (minusinf p)) \ (\ (e,c) \ set (\ p). \ j\ {1 .. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j)))))" - (is "(\(x::int). ?P x) = ((\ j\ {1.. \ p}. ?MP j)\(\ (e,c) \ ?R. \ j\ _. ?SP c e j))" - is "?lhs = (?MD \ ?RD)" is "?lhs = ?rhs") -proof- - let ?d= "\ p" - from \[OF lp] have d:"d\ p ?d" and dp: "?d > 0" by auto - { assume H:"?MD" hence th:"\ (x::int). ?MP x" by blast - from H minusinf_ex[OF lp th] have ?thesis by blast} - moreover - { fix e c j assume exR:"(e,c) \ ?R" and jD:"j\ {1 .. c*?d}" and spx:"?SP c e j" - from exR \_l[OF lp] have nb: "numbound0 e" and ei:"isint e (real i#bs)" and cp: "c > 0" - by auto - have "isint (C j) (real i#bs)" by (simp add: isint_iff) - with isint_add[OF numbound0_gen[OF nb ei,rule_format, where y="real i"]] - have eji:"isint (Add e (C j)) (real i#bs)" by simp - from nb have nb': "numbound0 (Add e (C j))" by simp - from spx bound0_I[OF \_nb[OF lp nb', where k="c"], where bs="bs" and b="a" and b'="real i"] - have spx': "Ifm (real i # bs) (\ p c (Add e (C j)))" by blast - from spx' have rcdej:"real c rdvd (Inum (real i#bs) (Add e (C j)))" - and sr:"Ifm (real i#bs) (\\ p (Add e (C j),c))" by (simp add: \_def)+ - from rcdej eji[simplified isint_iff] - have "real c rdvd real (floor (Inum (real i#bs) (Add e (C j))))" by simp - hence cdej:"c dvd floor (Inum (real i#bs) (Add e (C j)))" by (simp only: int_rdvd_iff) - from cp have cp': "real c > 0" by simp - from \\[OF lp cp' nb' eji cdej] spx' have "?P (\Inum (real i # bs) (Add e (C j))\ div c)" - by (simp add: \_def) - hence ?lhs by blast - with exR jD spx have ?thesis by blast} - moreover - { fix x assume px: "?P x" and nob: "\ ?RD" - from iszlfm_gen [OF lp,rule_format, where y="a"] have lp':"iszlfm p (a#bs)" . - from \'[OF lp' d dp, rule_format, OF nob] have th:"\ x. ?P x \ ?P (x - ?d)" by blast - from minusinf_inf[OF lp] obtain z where z:"\ x 0" by arith - from decr_lemma[OF dp,where x="x" and z="z"] - decr_mult_lemma[OF dp th zp, rule_format, OF px] z have th:"\ x. ?MP x" by auto - with minusinf_bex[OF lp] px nob have ?thesis by blast} - ultimately show ?thesis by blast -qed - -lemma mirror_\\: assumes lp: "iszlfm p (a#bs)" - shows "(\ (t,k). (Inum (a#bs) t, k)) ` set (\\ p) = (\ (t,k). (Inum (a#bs) t,k)) ` set (\ (mirror p))" -using lp -by (induct p rule: mirror.induct, simp_all add: split_def image_Un ) - -text {* The @{text "\"} part*} - -text{* Linearity for fm where Bound 0 ranges over @{text "\"}*} -consts - isrlfm :: "fm \ bool" (* Linearity test for fm *) -recdef isrlfm "measure size" - "isrlfm (And p q) = (isrlfm p \ isrlfm q)" - "isrlfm (Or p q) = (isrlfm p \ isrlfm q)" - "isrlfm (Eq (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (NEq (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Lt (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Le (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Gt (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Ge (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm p = (isatom p \ (bound0 p))" - -constdefs fp :: "fm \ int \ num \ int \ fm" - "fp p n s j \ (if n > 0 then - (And p (And (Ge (CN 0 n (Sub s (Add (Floor s) (C j))))) - (Lt (CN 0 n (Sub s (Add (Floor s) (C (j+1)))))))) - else - (And p (And (Le (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C j))))) - (Gt (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C (j + 1)))))))))" - - (* splits the bounded from the unbounded part*) -consts rsplit0 :: "num \ (fm \ int \ num) list" -recdef rsplit0 "measure num_size" - "rsplit0 (Bound 0) = [(T,1,C 0)]" - "rsplit0 (Add a b) = (let acs = rsplit0 a ; bcs = rsplit0 b - in map (\ ((p,n,t),(q,m,s)). (And p q, n+m, Add t s)) [(a,b). a\acs,b\bcs])" - "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))" - "rsplit0 (Neg a) = map (\ (p,n,s). (p,-n,Neg s)) (rsplit0 a)" - "rsplit0 (Floor a) = foldl (op @) [] (map - (\ (p,n,s). if n=0 then [(p,0,Floor s)] - else (map (\ j. (fp p n s j, 0, Add (Floor s) (C j))) (if n > 0 then iupt (0,n) else iupt(n,0)))) - (rsplit0 a))" - "rsplit0 (CN 0 c a) = map (\ (p,n,s). (p,n+c,s)) (rsplit0 a)" - "rsplit0 (CN m c a) = map (\ (p,n,s). (p,n,CN m c s)) (rsplit0 a)" - "rsplit0 (CF c t s) = rsplit0 (Add (Mul c (Floor t)) s)" - "rsplit0 (Mul c a) = map (\ (p,n,s). (p,c*n,Mul c s)) (rsplit0 a)" - "rsplit0 t = [(T,0,t)]" - -lemma not_rl[simp]: "isrlfm p \ isrlfm (not p)" - by (induct p rule: isrlfm.induct, auto) -lemma conj_rl[simp]: "isrlfm p \ isrlfm q \ isrlfm (conj p q)" - using conj_def by (cases p, auto) -lemma disj_rl[simp]: "isrlfm p \ isrlfm q \ isrlfm (disj p q)" - using disj_def by (cases p, auto) - - -lemma rsplit0_cs: - shows "\ (p,n,s) \ set (rsplit0 t). - (Ifm (x#bs) p \ (Inum (x#bs) t = Inum (x#bs) (CN 0 n s))) \ numbound0 s \ isrlfm p" - (is "\ (p,n,s) \ ?SS t. (?I p \ ?N t = ?N (CN 0 n s)) \ _ \ _ ") -proof(induct t rule: rsplit0.induct) - case (5 a) - let ?p = "\ (p,n,s) j. fp p n s j" - let ?f = "(\ (p,n,s) j. (?p (p,n,s) j, (0::int),Add (Floor s) (C j)))" - let ?J = "\ n. if n>0 then iupt (0,n) else iupt (n,0)" - let ?ff=" (\ (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))" - have int_cases: "\ (i::int). i= 0 \ i < 0 \ i > 0" by arith - have U1: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) = - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)]))" by auto - have U2': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n>0}. - ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))" by auto - hence U2: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) = - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). - set (map (?f(p,n,s)) (iupt(0,n)))))" - proof- - fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g - assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" - thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" - by (auto simp add: split_def) - qed - have U3': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n<0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(n,0))" - by auto - hence U3: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))) = - (UNION {(p,n,s). (p,n,s)\ ?SS a\n<0} (\(p,n,s). set (map (?f(p,n,s)) (iupt(n,0)))))" - proof- - fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g - assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" - thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" - by (auto simp add: split_def) - qed - have "?SS (Floor a) = UNION (?SS a) (\x. set (?ff x))" - by (auto simp add: foldl_conv_concat) - also have "\ = UNION (?SS a) (\ (p,n,s). set (?ff (p,n,s)))" by auto - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))))" - using int_cases[rule_format] by blast - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)])) Un - (UNION {(p,n,s). (p,n,s)\ ?SS a\n>0} (\(p,n,s). set(map(?f(p,n,s)) (iupt(0,n))))) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). - set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3) - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). (?f(p,n,s)) ` {0 .. n})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). (?f(p,n,s)) ` {n .. 0})))" - by (simp only: set_map iupt_set set.simps) - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast - finally - have FS: "?SS (Floor a) = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast - show ?case - proof(simp only: FS, clarsimp simp del: Ifm.simps Inum.simps, -) - fix p n s - let ?ths = "(?I p \ (?N (Floor a) = ?N (CN 0 n s))) \ numbound0 s \ isrlfm p" - assume "(\ba. (p, 0, ba) \ set (rsplit0 a) \ n = 0 \ s = Floor ba) \ - (\ab ac ba. - (ab, ac, ba) \ set (rsplit0 a) \ - 0 < ac \ - (\j. p = fp ab ac ba j \ - n = 0 \ s = Add (Floor ba) (C j) \ 0 \ j \ j \ ac)) \ - (\ab ac ba. - (ab, ac, ba) \ set (rsplit0 a) \ - ac < 0 \ - (\j. p = fp ab ac ba j \ - n = 0 \ s = Add (Floor ba) (C j) \ ac \ j \ j \ 0))" - moreover - {fix s' - assume "(p, 0, s') \ ?SS a" and "n = 0" and "s = Floor s'" - hence ?ths using prems by auto} - moreover - { fix p' n' s' j - assume pns: "(p', n', s') \ ?SS a" - and np: "0 < n'" - and p_def: "p = ?p (p',n',s') j" - and n0: "n = 0" - and s_def: "s = (Add (Floor s') (C j))" - and jp: "0 \ j" and jn: "j \ n'" - from prems pns have H:"(Ifm ((x\real) # (bs\real list)) p' \ - Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \ - numbound0 s' \ isrlfm p'" by blast - hence nb: "numbound0 s'" by simp - from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numsub_nb) - let ?nxs = "CN 0 n' s'" - let ?l = "floor (?N s') + j" - from H - have "?I (?p (p',n',s') j) \ - (((?N ?nxs \ real ?l) \ (?N ?nxs < real (?l + 1))) \ (?N a = ?N ?nxs ))" - by (simp add: fp_def np algebra_simps numsub numadd numfloor) - also have "\ \ ((floor (?N ?nxs) = ?l) \ (?N a = ?N ?nxs ))" - using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp - moreover - have "\ \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" by simp - ultimately have "?I (?p (p',n',s') j) \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" - by blast - with s_def n0 p_def nb nf have ?ths by auto} - moreover - {fix p' n' s' j - assume pns: "(p', n', s') \ ?SS a" - and np: "n' < 0" - and p_def: "p = ?p (p',n',s') j" - and n0: "n = 0" - and s_def: "s = (Add (Floor s') (C j))" - and jp: "n' \ j" and jn: "j \ 0" - from prems pns have H:"(Ifm ((x\real) # (bs\real list)) p' \ - Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \ - numbound0 s' \ isrlfm p'" by blast - hence nb: "numbound0 s'" by simp - from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numneg_nb) - let ?nxs = "CN 0 n' s'" - let ?l = "floor (?N s') + j" - from H - have "?I (?p (p',n',s') j) \ - (((?N ?nxs \ real ?l) \ (?N ?nxs < real (?l + 1))) \ (?N a = ?N ?nxs ))" - by (simp add: np fp_def algebra_simps numneg numfloor numadd numsub) - also have "\ \ ((floor (?N ?nxs) = ?l) \ (?N a = ?N ?nxs ))" - using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp - moreover - have "\ \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" by simp - ultimately have "?I (?p (p',n',s') j) \ (?N (Floor a) = ?N ((Add (Floor s') (C j))))" - by blast - with s_def n0 p_def nb nf have ?ths by auto} - ultimately show ?ths by auto - qed -next - case (3 a b) then show ?case - apply auto - apply (erule_tac x = "(aa, aaa, ba)" in ballE) apply simp_all - apply (erule_tac x = "(ab, ac, baa)" in ballE) apply simp_all - done -qed (auto simp add: Let_def split_def algebra_simps conj_rl) - -lemma real_in_int_intervals: - assumes xb: "real m \ x \ x < real ((n::int) + 1)" - shows "\ j\ {m.. n}. real j \ x \ x < real (j+1)" (is "\ j\ ?N. ?P j") -by (rule bexI[where P="?P" and x="floor x" and A="?N"]) -(auto simp add: floor_less_eq[where x="x" and a="n+1", simplified] xb[simplified] floor_mono2[where x="real m" and y="x", OF conjunct1[OF xb], simplified floor_real_of_int[where n="m"]]) - -lemma rsplit0_complete: - assumes xp:"0 \ x" and x1:"x < 1" - shows "\ (p,n,s) \ set (rsplit0 t). Ifm (x#bs) p" (is "\ (p,n,s) \ ?SS t. ?I p") -proof(induct t rule: rsplit0.induct) - case (2 a b) - from prems have "\ (pa,na,sa) \ ?SS a. ?I pa" by auto - then obtain "pa" "na" "sa" where pa: "(pa,na,sa)\ ?SS a \ ?I pa" by blast - from prems have "\ (pb,nb,sb) \ ?SS b. ?I pb" by auto - then obtain "pb" "nb" "sb" where pb: "(pb,nb,sb)\ ?SS b \ ?I pb" by blast - from pa pb have th: "((pa,na,sa),(pb,nb,sb)) \ set[(x,y). x\rsplit0 a, y\rsplit0 b]" - by (auto) - let ?f="(\ ((p,n,t),(q,m,s)). (And p q, n+m, Add t s))" - from imageI[OF th, where f="?f"] have "?f ((pa,na,sa),(pb,nb,sb)) \ ?SS (Add a b)" - by (simp add: Let_def) - hence "(And pa pb, na +nb, Add sa sb) \ ?SS (Add a b)" by simp - moreover from pa pb have "?I (And pa pb)" by simp - ultimately show ?case by blast -next - case (5 a) - let ?p = "\ (p,n,s) j. fp p n s j" - let ?f = "(\ (p,n,s) j. (?p (p,n,s) j, (0::int),(Add (Floor s) (C j))))" - let ?J = "\ n. if n>0 then iupt (0,n) else iupt (n,0)" - let ?ff=" (\ (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))" - have int_cases: "\ (i::int). i= 0 \ i < 0 \ i > 0" by arith - have U1: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)]))" by auto - have U2': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n>0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))" - by auto - hence U2: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(0,n)))))" - proof- - fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g - assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" - thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" - by (auto simp add: split_def) - qed - have U3': "\ (p,n,s) \ {(p,n,s). (p,n,s) \ ?SS a \ n<0}. ?ff (p,n,s) = map (?f(p,n,s)) (iupt(n,0))" - by auto - hence U3: "(UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))) = (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(n,0)))))" - proof- - fix M :: "('a\'b\'c) set" and f :: "('a\'b\'c) \ 'd list" and g - assume "\ (a,b,c) \ M. f (a,b,c) = g a b c" - thus "(UNION M (\ (a,b,c). set (f (a,b,c)))) = (UNION M (\ (a,b,c). set (g a b c)))" - by (auto simp add: split_def) - qed - - have "?SS (Floor a) = UNION (?SS a) (\x. set (?ff x))" by (auto simp add: foldl_conv_concat) - also have "\ = UNION (?SS a) (\ (p,n,s). set (?ff (p,n,s)))" by auto - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set (?ff (p,n,s)))) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (?ff (p,n,s)))) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (?ff (p,n,s)))))" - using int_cases[rule_format] by blast - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). set [(p,0,Floor s)])) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(0,n))))) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3) - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). (?f(p,n,s)) ` {0 .. n})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). (?f(p,n,s)) ` {n .. 0})))" - by (simp only: set_map iupt_set set.simps) - also have "\ = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast - finally - have FS: "?SS (Floor a) = - ((UNION {(p,n,s). (p,n,s) \ ?SS a \ n=0} (\ (p,n,s). {(p,0,Floor s)})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n>0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {0 .. n}})) Un - (UNION {(p,n,s). (p,n,s) \ ?SS a \ n<0} (\ (p,n,s). {?f(p,n,s) j| j. j\ {n .. 0}})))" by blast - from prems have "\ (p,n,s) \ ?SS a. ?I p" by auto - then obtain "p" "n" "s" where pns: "(p,n,s) \ ?SS a \ ?I p" by blast - let ?N = "\ t. Inum (x#bs) t" - from rsplit0_cs[rule_format] pns have ans:"(?N a = ?N (CN 0 n s)) \ numbound0 s \ isrlfm p" - by auto - - have "n=0 \ n >0 \ n <0" by arith - moreover {assume "n=0" hence ?case using pns by (simp only: FS) auto } - moreover - { - assume np: "n > 0" - from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) \ ?N s" by simp - also from mult_left_mono[OF xp] np have "?N s \ real n * x + ?N s" by simp - finally have "?N (Floor s) \ real n * x + ?N s" . - moreover - {from mult_strict_left_mono[OF x1] np - have "real n *x + ?N s < real n + ?N s" by simp - also from real_of_int_floor_add_one_gt[where r="?N s"] - have "\ < real n + ?N (Floor s) + 1" by simp - finally have "real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp} - ultimately have "?N (Floor s) \ real n *x + ?N s\ real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp - hence th: "0 \ real n *x + ?N s - ?N (Floor s) \ real n *x + ?N s - ?N (Floor s) < real (n+1)" by simp - from real_in_int_intervals th have "\ j\ {0 .. n}. real j \ real n *x + ?N s - ?N (Floor s)\ real n *x + ?N s - ?N (Floor s) < real (j+1)" by simp - - hence "\ j\ {0 .. n}. 0 \ real n *x + ?N s - ?N (Floor s) - real j \ real n *x + ?N s - ?N (Floor s) - real (j+1) < 0" - by(simp only: myl[rule_format, where b="real n * x + Inum (x # bs) s - Inum (x # bs) (Floor s)"] less_iff_diff_less_0[where a="real n *x + ?N s - ?N (Floor s)"]) - hence "\ j\ {0.. n}. ?I (?p (p,n,s) j)" - using pns by (simp add: fp_def np algebra_simps numsub numadd) - then obtain "j" where j_def: "j\ {0 .. n} \ ?I (?p (p,n,s) j)" by blast - hence "\x \ {?p (p,n,s) j |j. 0\ j \ j \ n }. ?I x" by auto - hence ?case using pns - by (simp only: FS,simp add: bex_Un) - (rule disjI2, rule disjI1,rule exI [where x="p"], - rule exI [where x="n"],rule exI [where x="s"],simp_all add: np) - } - moreover - { assume nn: "n < 0" hence np: "-n >0" by simp - from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) + 1 > ?N s" by simp - moreover from mult_left_mono_neg[OF xp] nn have "?N s \ real n * x + ?N s" by simp - ultimately have "?N (Floor s) + 1 > real n * x + ?N s" by arith - moreover - {from mult_strict_left_mono_neg[OF x1, where c="real n"] nn - have "real n *x + ?N s \ real n + ?N s" by simp - moreover from real_of_int_floor_le[where r="?N s"] have "real n + ?N s \ real n + ?N (Floor s)" by simp - ultimately have "real n *x + ?N s \ ?N (Floor s) + real n" - by (simp only: algebra_simps)} - ultimately have "?N (Floor s) + real n \ real n *x + ?N s\ real n *x + ?N s < ?N (Floor s) + real (1::int)" by simp - hence th: "real n \ real n *x + ?N s - ?N (Floor s) \ real n *x + ?N s - ?N (Floor s) < real (1::int)" by simp - have th1: "\ (a::real). (- a > 0) = (a < 0)" by auto - have th2: "\ (a::real). (0 \ - a) = (a \ 0)" by auto - from real_in_int_intervals th have "\ j\ {n .. 0}. real j \ real n *x + ?N s - ?N (Floor s)\ real n *x + ?N s - ?N (Floor s) < real (j+1)" by simp - - hence "\ j\ {n .. 0}. 0 \ real n *x + ?N s - ?N (Floor s) - real j \ real n *x + ?N s - ?N (Floor s) - real (j+1) < 0" - by(simp only: myl[rule_format, where b="real n * x + Inum (x # bs) s - Inum (x # bs) (Floor s)"] less_iff_diff_less_0[where a="real n *x + ?N s - ?N (Floor s)"]) - hence "\ j\ {n .. 0}. 0 \ - (real n *x + ?N s - ?N (Floor s) - real j) \ - (real n *x + ?N s - ?N (Floor s) - real (j+1)) > 0" by (simp only: th1[rule_format] th2[rule_format]) - hence "\ j\ {n.. 0}. ?I (?p (p,n,s) j)" - using pns by (simp add: fp_def nn diff_def add_ac mult_ac numfloor numadd numneg - del: diff_less_0_iff_less diff_le_0_iff_le) - then obtain "j" where j_def: "j\ {n .. 0} \ ?I (?p (p,n,s) j)" by blast - hence "\x \ {?p (p,n,s) j |j. n\ j \ j \ 0 }. ?I x" by auto - hence ?case using pns - by (simp only: FS,simp add: bex_Un) - (rule disjI2, rule disjI2,rule exI [where x="p"], - rule exI [where x="n"],rule exI [where x="s"],simp_all add: nn) - } - ultimately show ?case by blast -qed (auto simp add: Let_def split_def) - - (* Linearize a formula where Bound 0 ranges over [0,1) *) - -constdefs rsplit :: "(int \ num \ fm) \ num \ fm" - "rsplit f a \ foldr disj (map (\ (\, n, s). conj \ (f n s)) (rsplit0 a)) F" - -lemma foldr_disj_map: "Ifm bs (foldr disj (map f xs) F) = (\ x \ set xs. Ifm bs (f x))" -by(induct xs, simp_all) - -lemma foldr_conj_map: "Ifm bs (foldr conj (map f xs) T) = (\ x \ set xs. Ifm bs (f x))" -by(induct xs, simp_all) - -lemma foldr_disj_map_rlfm: - assumes lf: "\ n s. numbound0 s \ isrlfm (f n s)" - and \: "\ (\,n,s) \ set xs. numbound0 s \ isrlfm \" - shows "isrlfm (foldr disj (map (\ (\, n, s). conj \ (f n s)) xs) F)" -using lf \ by (induct xs, auto) - -lemma rsplit_ex: "Ifm bs (rsplit f a) = (\ (\,n,s) \ set (rsplit0 a). Ifm bs (conj \ (f n s)))" -using foldr_disj_map[where xs="rsplit0 a"] rsplit_def by (simp add: split_def) - -lemma rsplit_l: assumes lf: "\ n s. numbound0 s \ isrlfm (f n s)" - shows "isrlfm (rsplit f a)" -proof- - from rsplit0_cs[where t="a"] have th: "\ (\,n,s) \ set (rsplit0 a). numbound0 s \ isrlfm \" by blast - from foldr_disj_map_rlfm[OF lf th] rsplit_def show ?thesis by simp -qed - -lemma rsplit: - assumes xp: "x \ 0" and x1: "x < 1" - and f: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ (Ifm (x#bs) (f n s) = Ifm (x#bs) (g a))" - shows "Ifm (x#bs) (rsplit f a) = Ifm (x#bs) (g a)" -proof(auto) - let ?I = "\x p. Ifm (x#bs) p" - let ?N = "\ x t. Inum (x#bs) t" - assume "?I x (rsplit f a)" - hence "\ (\,n,s) \ set (rsplit0 a). ?I x (And \ (f n s))" using rsplit_ex by simp - then obtain "\" "n" "s" where fnsS:"(\,n,s) \ set (rsplit0 a)" and "?I x (And \ (f n s))" by blast - hence \: "?I x \" and fns: "?I x (f n s)" by auto - from rsplit0_cs[where t="a" and bs="bs" and x="x", rule_format, OF fnsS] \ - have th: "(?N x a = ?N x (CN 0 n s)) \ numbound0 s" by auto - from f[rule_format, OF th] fns show "?I x (g a)" by simp -next - let ?I = "\x p. Ifm (x#bs) p" - let ?N = "\ x t. Inum (x#bs) t" - assume ga: "?I x (g a)" - from rsplit0_complete[OF xp x1, where bs="bs" and t="a"] - obtain "\" "n" "s" where fnsS:"(\,n,s) \ set (rsplit0 a)" and fx: "?I x \" by blast - from rsplit0_cs[where t="a" and x="x" and bs="bs"] fnsS fx - have ans: "?N x a = ?N x (CN 0 n s)" and nb: "numbound0 s" by auto - with ga f have "?I x (f n s)" by auto - with rsplit_ex fnsS fx show "?I x (rsplit f a)" by auto -qed - -definition lt :: "int \ num \ fm" where - lt_def: "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) - else (Gt (CN 0 (-c) (Neg t))))" - -definition le :: "int \ num \ fm" where - le_def: "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) - else (Ge (CN 0 (-c) (Neg t))))" - -definition gt :: "int \ num \ fm" where - gt_def: "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) - else (Lt (CN 0 (-c) (Neg t))))" - -definition ge :: "int \ num \ fm" where - ge_def: "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) - else (Le (CN 0 (-c) (Neg t))))" - -definition eq :: "int \ num \ fm" where - eq_def: "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) - else (Eq (CN 0 (-c) (Neg t))))" - -definition neq :: "int \ num \ fm" where - neq_def: "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) - else (NEq (CN 0 (-c) (Neg t))))" - -lemma lt_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (lt n s) = Ifm (x#bs) (Lt a)" - (is "\ a n s . ?N a = ?N (CN 0 n s) \ _\ ?I (lt n s) = ?I (Lt a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" - show "?I (lt n s) = ?I (Lt a)" using H by (cases "n=0", (simp add: lt_def)) - (cases "n > 0", simp_all add: lt_def algebra_simps myless[rule_format, where b="0"]) -qed - -lemma lt_l: "isrlfm (rsplit lt a)" - by (rule rsplit_l[where f="lt" and a="a"], auto simp add: lt_def, - case_tac s, simp_all, case_tac "nat", simp_all) - -lemma le_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (le n s) = Ifm (x#bs) (Le a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (le n s) = ?I (Le a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" - show "?I (le n s) = ?I (Le a)" using H by (cases "n=0", (simp add: le_def)) - (cases "n > 0", simp_all add: le_def algebra_simps myl[rule_format, where b="0"]) -qed - -lemma le_l: "isrlfm (rsplit le a)" - by (rule rsplit_l[where f="le" and a="a"], auto simp add: le_def) -(case_tac s, simp_all, case_tac "nat",simp_all) - -lemma gt_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (gt n s) = Ifm (x#bs) (Gt a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (gt n s) = ?I (Gt a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" - show "?I (gt n s) = ?I (Gt a)" using H by (cases "n=0", (simp add: gt_def)) - (cases "n > 0", simp_all add: gt_def algebra_simps myless[rule_format, where b="0"]) -qed -lemma gt_l: "isrlfm (rsplit gt a)" - by (rule rsplit_l[where f="gt" and a="a"], auto simp add: gt_def) -(case_tac s, simp_all, case_tac "nat", simp_all) - -lemma ge_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (ge n s) = Ifm (x#bs) (Ge a)" (is "\ a n s . ?N a = ?N (CN 0 n s) \ _ \ ?I (ge n s) = ?I (Ge a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" - show "?I (ge n s) = ?I (Ge a)" using H by (cases "n=0", (simp add: ge_def)) - (cases "n > 0", simp_all add: ge_def algebra_simps myl[rule_format, where b="0"]) -qed -lemma ge_l: "isrlfm (rsplit ge a)" - by (rule rsplit_l[where f="ge" and a="a"], auto simp add: ge_def) -(case_tac s, simp_all, case_tac "nat", simp_all) - -lemma eq_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (eq n s) = Ifm (x#bs) (Eq a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (eq n s) = ?I (Eq a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" - show "?I (eq n s) = ?I (Eq a)" using H by (auto simp add: eq_def algebra_simps) -qed -lemma eq_l: "isrlfm (rsplit eq a)" - by (rule rsplit_l[where f="eq" and a="a"], auto simp add: eq_def) -(case_tac s, simp_all, case_tac"nat", simp_all) - -lemma neq_mono: "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (neq n s) = Ifm (x#bs) (NEq a)" (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (neq n s) = ?I (NEq a)") -proof(clarify) - fix a n s bs - assume H: "?N a = ?N (CN 0 n s)" - show "?I (neq n s) = ?I (NEq a)" using H by (auto simp add: neq_def algebra_simps) -qed - -lemma neq_l: "isrlfm (rsplit neq a)" - by (rule rsplit_l[where f="neq" and a="a"], auto simp add: neq_def) -(case_tac s, simp_all, case_tac"nat", simp_all) - -lemma small_le: - assumes u0:"0 \ u" and u1: "u < 1" - shows "(-u \ real (n::int)) = (0 \ n)" -using u0 u1 by auto - -lemma small_lt: - assumes u0:"0 \ u" and u1: "u < 1" - shows "(real (n::int) < real (m::int) - u) = (n < m)" -using u0 u1 by auto - -lemma rdvd01_cs: - assumes up: "u \ 0" and u1: "u<1" and np: "real n > 0" - shows "(real (i::int) rdvd real (n::int) * u - s) = (\ j\ {0 .. n - 1}. real n * u = s - real (floor s) + real j \ real i rdvd real (j - floor s))" (is "?lhs = ?rhs") -proof- - let ?ss = "s - real (floor s)" - from real_of_int_floor_add_one_gt[where r="s", simplified myless[rule_format,where a="s"]] - real_of_int_floor_le[where r="s"] have ss0:"?ss \ 0" and ss1:"?ss < 1" - by (auto simp add: myl[rule_format, where b="s", symmetric] myless[rule_format, where a="?ss"]) - from np have n0: "real n \ 0" by simp - from mult_left_mono[OF up n0] mult_strict_left_mono[OF u1 np] - have nu0:"real n * u - s \ -s" and nun:"real n * u -s < real n - s" by auto - from int_rdvd_real[where i="i" and x="real (n::int) * u - s"] - have "real i rdvd real n * u - s = - (i dvd floor (real n * u -s) \ (real (floor (real n * u - s)) = real n * u - s ))" - (is "_ = (?DE)" is "_ = (?D \ ?E)") by simp - also have "\ = (?DE \ real(floor (real n * u - s) + floor s)\ -?ss - \ real(floor (real n * u - s) + floor s)< real n - ?ss)" (is "_=(?DE \real ?a \ _ \ real ?a < _)") - using nu0 nun by auto - also have "\ = (?DE \ ?a \ 0 \ ?a < n)" by(simp only: small_le[OF ss0 ss1] small_lt[OF ss0 ss1]) - also have "\ = (?DE \ (\ j\ {0 .. (n - 1)}. ?a = j))" by simp - also have "\ = (?DE \ (\ j\ {0 .. (n - 1)}. real (\real n * u - s\) = real j - real \s\ ))" - by (simp only: algebra_simps real_of_int_diff[symmetric] real_of_int_inject del: real_of_int_diff) - also have "\ = ((\ j\ {0 .. (n - 1)}. real n * u - s = real j - real \s\ \ real i rdvd real n * u - s))" using int_rdvd_iff[where i="i" and t="\real n * u - s\"] - by (auto cong: conj_cong) - also have "\ = ?rhs" by(simp cong: conj_cong) (simp add: algebra_simps ) - finally show ?thesis . -qed - -definition - DVDJ:: "int \ int \ num \ fm" -where - DVDJ_def: "DVDJ i n s = (foldr disj (map (\ j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (Dvd i (Sub (C j) (Floor (Neg s))))) (iupt(0,n - 1))) F)" - -definition - NDVDJ:: "int \ int \ num \ fm" -where - NDVDJ_def: "NDVDJ i n s = (foldr conj (map (\ j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (NDvd i (Sub (C j) (Floor (Neg s))))) (iupt(0,n - 1))) T)" - -lemma DVDJ_DVD: - assumes xp:"x\ 0" and x1: "x < 1" and np:"real n > 0" - shows "Ifm (x#bs) (DVDJ i n s) = Ifm (x#bs) (Dvd i (CN 0 n s))" -proof- - let ?f = "\ j. conj (Eq(CN 0 n (Add s (Sub(Floor (Neg s)) (C j))))) (Dvd i (Sub (C j) (Floor (Neg s))))" - let ?s= "Inum (x#bs) s" - from foldr_disj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"] - have "Ifm (x#bs) (DVDJ i n s) = (\ j\ {0 .. (n - 1)}. Ifm (x#bs) (?f j))" - by (simp add: iupt_set np DVDJ_def del: iupt.simps) - also have "\ = (\ j\ {0 .. (n - 1)}. real n * x = (- ?s) - real (floor (- ?s)) + real j \ real i rdvd real (j - floor (- ?s)))" by (simp add: algebra_simps diff_def[symmetric]) - also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] - have "\ = (real i rdvd real n * x - (-?s))" by simp - finally show ?thesis by simp -qed - -lemma NDVDJ_NDVD: - assumes xp:"x\ 0" and x1: "x < 1" and np:"real n > 0" - shows "Ifm (x#bs) (NDVDJ i n s) = Ifm (x#bs) (NDvd i (CN 0 n s))" -proof- - let ?f = "\ j. disj(NEq(CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) (NDvd i (Sub (C j) (Floor(Neg s))))" - let ?s= "Inum (x#bs) s" - from foldr_conj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"] - have "Ifm (x#bs) (NDVDJ i n s) = (\ j\ {0 .. (n - 1)}. Ifm (x#bs) (?f j))" - by (simp add: iupt_set np NDVDJ_def del: iupt.simps) - also have "\ = (\ (\ j\ {0 .. (n - 1)}. real n * x = (- ?s) - real (floor (- ?s)) + real j \ real i rdvd real (j - floor (- ?s))))" by (simp add: algebra_simps diff_def[symmetric]) - also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] - have "\ = (\ (real i rdvd real n * x - (-?s)))" by simp - finally show ?thesis by simp -qed - -lemma foldr_disj_map_rlfm2: - assumes lf: "\ n . isrlfm (f n)" - shows "isrlfm (foldr disj (map f xs) F)" -using lf by (induct xs, auto) -lemma foldr_And_map_rlfm2: - assumes lf: "\ n . isrlfm (f n)" - shows "isrlfm (foldr conj (map f xs) T)" -using lf by (induct xs, auto) - -lemma DVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s" - shows "isrlfm (DVDJ i n s)" -proof- - let ?f="\j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) - (Dvd i (Sub (C j) (Floor (Neg s))))" - have th: "\ j. isrlfm (?f j)" using nb np by auto - from DVDJ_def foldr_disj_map_rlfm2[OF th] show ?thesis by simp -qed - -lemma NDVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s" - shows "isrlfm (NDVDJ i n s)" -proof- - let ?f="\j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j))))) - (NDvd i (Sub (C j) (Floor (Neg s))))" - have th: "\ j. isrlfm (?f j)" using nb np by auto - from NDVDJ_def foldr_And_map_rlfm2[OF th] show ?thesis by auto -qed - -definition DVD :: "int \ int \ num \ fm" where - DVD_def: "DVD i c t = - (if i=0 then eq c t else - if c = 0 then (Dvd i t) else if c >0 then DVDJ (abs i) c t else DVDJ (abs i) (-c) (Neg t))" - -definition NDVD :: "int \ int \ num \ fm" where - "NDVD i c t = - (if i=0 then neq c t else - if c = 0 then (NDvd i t) else if c >0 then NDVDJ (abs i) c t else NDVDJ (abs i) (-c) (Neg t))" - -lemma DVD_mono: - assumes xp: "0\ x" and x1: "x < 1" - shows "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (DVD i n s) = Ifm (x#bs) (Dvd i a)" - (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (DVD i n s) = ?I (Dvd i a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s" - let ?th = "?I (DVD i n s) = ?I (Dvd i a)" - have "i=0 \ (i\0 \ n=0) \ (i\0 \ n < 0) \ (i\0 \ n > 0)" by arith - moreover {assume iz: "i=0" hence ?th using eq_mono[rule_format, OF conjI[OF H nb]] - by (simp add: DVD_def rdvd_left_0_eq)} - moreover {assume inz: "i\0" and "n=0" hence ?th by (simp add: H DVD_def) } - moreover {assume inz: "i\0" and "n<0" hence ?th - by (simp add: DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1 - rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } - moreover {assume inz: "i\0" and "n>0" hence ?th by (simp add:DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1)} - ultimately show ?th by blast -qed - -lemma NDVD_mono: assumes xp: "0\ x" and x1: "x < 1" - shows "\ a n s. Inum (x#bs) a = Inum (x#bs) (CN 0 n s) \ numbound0 s \ Ifm (x#bs) (NDVD i n s) = Ifm (x#bs) (NDvd i a)" - (is "\ a n s. ?N a = ?N (CN 0 n s) \ _ \ ?I (NDVD i n s) = ?I (NDvd i a)") -proof(clarify) - fix a n s - assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s" - let ?th = "?I (NDVD i n s) = ?I (NDvd i a)" - have "i=0 \ (i\0 \ n=0) \ (i\0 \ n < 0) \ (i\0 \ n > 0)" by arith - moreover {assume iz: "i=0" hence ?th using neq_mono[rule_format, OF conjI[OF H nb]] - by (simp add: NDVD_def rdvd_left_0_eq)} - moreover {assume inz: "i\0" and "n=0" hence ?th by (simp add: H NDVD_def) } - moreover {assume inz: "i\0" and "n<0" hence ?th - by (simp add: NDVD_def H NDVDJ_NDVD[OF xp x1] rdvd_abs1 - rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } - moreover {assume inz: "i\0" and "n>0" hence ?th - by (simp add:NDVD_def H NDVDJ_NDVD[OF xp x1] rdvd_abs1)} - ultimately show ?th by blast -qed - -lemma DVD_l: "isrlfm (rsplit (DVD i) a)" - by (rule rsplit_l[where f="DVD i" and a="a"], auto simp add: DVD_def eq_def DVDJ_l) -(case_tac s, simp_all, case_tac "nat", simp_all) - -lemma NDVD_l: "isrlfm (rsplit (NDVD i) a)" - by (rule rsplit_l[where f="NDVD i" and a="a"], auto simp add: NDVD_def neq_def NDVDJ_l) -(case_tac s, simp_all, case_tac "nat", simp_all) - -consts rlfm :: "fm \ fm" -recdef rlfm "measure fmsize" - "rlfm (And p q) = conj (rlfm p) (rlfm q)" - "rlfm (Or p q) = disj (rlfm p) (rlfm q)" - "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)" - "rlfm (Iff p q) = disj (conj(rlfm p) (rlfm q)) (conj(rlfm (NOT p)) (rlfm (NOT q)))" - "rlfm (Lt a) = rsplit lt a" - "rlfm (Le a) = rsplit le a" - "rlfm (Gt a) = rsplit gt a" - "rlfm (Ge a) = rsplit ge a" - "rlfm (Eq a) = rsplit eq a" - "rlfm (NEq a) = rsplit neq a" - "rlfm (Dvd i a) = rsplit (\ t. DVD i t) a" - "rlfm (NDvd i a) = rsplit (\ t. NDVD i t) a" - "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))" - "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))" - "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))" - "rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))" - "rlfm (NOT (NOT p)) = rlfm p" - "rlfm (NOT T) = F" - "rlfm (NOT F) = T" - "rlfm (NOT (Lt a)) = simpfm (rlfm (Ge a))" - "rlfm (NOT (Le a)) = simpfm (rlfm (Gt a))" - "rlfm (NOT (Gt a)) = simpfm (rlfm (Le a))" - "rlfm (NOT (Ge a)) = simpfm (rlfm (Lt a))" - "rlfm (NOT (Eq a)) = simpfm (rlfm (NEq a))" - "rlfm (NOT (NEq a)) = simpfm (rlfm (Eq a))" - "rlfm (NOT (Dvd i a)) = simpfm (rlfm (NDvd i a))" - "rlfm (NOT (NDvd i a)) = simpfm (rlfm (Dvd i a))" - "rlfm p = p" (hints simp add: fmsize_pos) - -lemma bound0at_l : "\isatom p ; bound0 p\ \ isrlfm p" - by (induct p rule: isrlfm.induct, auto) -lemma zgcd_le1: assumes ip: "0 < i" shows "zgcd i j \ i" -proof- - from zgcd_zdvd1 have th: "zgcd i j dvd i" by blast - from zdvd_imp_le[OF th ip] show ?thesis . -qed - - -lemma simpfm_rl: "isrlfm p \ isrlfm (simpfm p)" -proof (induct p) - case (Lt a) - hence "bound0 (Lt a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" - by (cases a,simp_all, case_tac "nat", simp_all) - moreover - {assume "bound0 (Lt a)" hence bn:"bound0 (simpfm (Lt a))" - using simpfm_bound0 by blast - have "isatom (simpfm (Lt a))" by (cases "simpnum a", auto simp add: Let_def) - with bn bound0at_l have ?case by blast} - moreover - {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" - { - assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" - with numgcd_pos[where t="CN 0 c (simpnum e)"] - have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp - from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" - by (simp add: numgcd_def zgcd_le1) - from prems have th': "c\0" by auto - from prems have cp: "c \ 0" by simp - from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] - have "0 < c div numgcd (CN 0 c (simpnum e))" by simp - } - with prems have ?case - by (simp add: Let_def reducecoeff_def reducecoeffh_numbound0)} - ultimately show ?case by blast -next - case (Le a) - hence "bound0 (Le a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" - by (cases a,simp_all, case_tac "nat", simp_all) - moreover - {assume "bound0 (Le a)" hence bn:"bound0 (simpfm (Le a))" - using simpfm_bound0 by blast - have "isatom (simpfm (Le a))" by (cases "simpnum a", auto simp add: Let_def) - with bn bound0at_l have ?case by blast} - moreover - {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" - { - assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" - with numgcd_pos[where t="CN 0 c (simpnum e)"] - have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp - from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" - by (simp add: numgcd_def zgcd_le1) - from prems have th': "c\0" by auto - from prems have cp: "c \ 0" by simp - from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] - have "0 < c div numgcd (CN 0 c (simpnum e))" by simp - } - with prems have ?case - by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} - ultimately show ?case by blast -next - case (Gt a) - hence "bound0 (Gt a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" - by (cases a,simp_all, case_tac "nat", simp_all) - moreover - {assume "bound0 (Gt a)" hence bn:"bound0 (simpfm (Gt a))" - using simpfm_bound0 by blast - have "isatom (simpfm (Gt a))" by (cases "simpnum a", auto simp add: Let_def) - with bn bound0at_l have ?case by blast} - moreover - {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" - { - assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" - with numgcd_pos[where t="CN 0 c (simpnum e)"] - have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp - from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" - by (simp add: numgcd_def zgcd_le1) - from prems have th': "c\0" by auto - from prems have cp: "c \ 0" by simp - from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] - have "0 < c div numgcd (CN 0 c (simpnum e))" by simp - } - with prems have ?case - by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} - ultimately show ?case by blast -next - case (Ge a) - hence "bound0 (Ge a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" - by (cases a,simp_all, case_tac "nat", simp_all) - moreover - {assume "bound0 (Ge a)" hence bn:"bound0 (simpfm (Ge a))" - using simpfm_bound0 by blast - have "isatom (simpfm (Ge a))" by (cases "simpnum a", auto simp add: Let_def) - with bn bound0at_l have ?case by blast} - moreover - {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" - { - assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" - with numgcd_pos[where t="CN 0 c (simpnum e)"] - have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp - from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" - by (simp add: numgcd_def zgcd_le1) - from prems have th': "c\0" by auto - from prems have cp: "c \ 0" by simp - from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] - have "0 < c div numgcd (CN 0 c (simpnum e))" by simp - } - with prems have ?case - by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} - ultimately show ?case by blast -next - case (Eq a) - hence "bound0 (Eq a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" - by (cases a,simp_all, case_tac "nat", simp_all) - moreover - {assume "bound0 (Eq a)" hence bn:"bound0 (simpfm (Eq a))" - using simpfm_bound0 by blast - have "isatom (simpfm (Eq a))" by (cases "simpnum a", auto simp add: Let_def) - with bn bound0at_l have ?case by blast} - moreover - {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" - { - assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" - with numgcd_pos[where t="CN 0 c (simpnum e)"] - have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp - from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" - by (simp add: numgcd_def zgcd_le1) - from prems have th': "c\0" by auto - from prems have cp: "c \ 0" by simp - from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] - have "0 < c div numgcd (CN 0 c (simpnum e))" by simp - } - with prems have ?case - by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} - ultimately show ?case by blast -next - case (NEq a) - hence "bound0 (NEq a) \ (\ c e. a = CN 0 c e \ c > 0 \ numbound0 e)" - by (cases a,simp_all, case_tac "nat", simp_all) - moreover - {assume "bound0 (NEq a)" hence bn:"bound0 (simpfm (NEq a))" - using simpfm_bound0 by blast - have "isatom (simpfm (NEq a))" by (cases "simpnum a", auto simp add: Let_def) - with bn bound0at_l have ?case by blast} - moreover - {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e" - { - assume cn1:"numgcd (CN 0 c (simpnum e)) \ 1" and cnz:"numgcd (CN 0 c (simpnum e)) \ 0" - with numgcd_pos[where t="CN 0 c (simpnum e)"] - have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp - from prems have th:"numgcd (CN 0 c (simpnum e)) \ c" - by (simp add: numgcd_def zgcd_le1) - from prems have th': "c\0" by auto - from prems have cp: "c \ 0" by simp - from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']] - have "0 < c div numgcd (CN 0 c (simpnum e))" by simp - } - with prems have ?case - by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)} - ultimately show ?case by blast -next - case (Dvd i a) hence "bound0 (Dvd i a)" by auto hence bn:"bound0 (simpfm (Dvd i a))" - using simpfm_bound0 by blast - have "isatom (simpfm (Dvd i a))" by (cases "simpnum a", auto simp add: Let_def split_def) - with bn bound0at_l show ?case by blast -next - case (NDvd i a) hence "bound0 (NDvd i a)" by auto hence bn:"bound0 (simpfm (NDvd i a))" - using simpfm_bound0 by blast - have "isatom (simpfm (NDvd i a))" by (cases "simpnum a", auto simp add: Let_def split_def) - with bn bound0at_l show ?case by blast -qed(auto simp add: conj_def imp_def disj_def iff_def Let_def simpfm_bound0 numadd_nb numneg_nb) - -lemma rlfm_I: - assumes qfp: "qfree p" - and xp: "0 \ x" and x1: "x < 1" - shows "(Ifm (x#bs) (rlfm p) = Ifm (x# bs) p) \ isrlfm (rlfm p)" - using qfp -by (induct p rule: rlfm.induct) -(auto simp add: rsplit[OF xp x1 lt_mono] lt_l rsplit[OF xp x1 le_mono] le_l rsplit[OF xp x1 gt_mono] gt_l - rsplit[OF xp x1 ge_mono] ge_l rsplit[OF xp x1 eq_mono] eq_l rsplit[OF xp x1 neq_mono] neq_l - rsplit[OF xp x1 DVD_mono[OF xp x1]] DVD_l rsplit[OF xp x1 NDVD_mono[OF xp x1]] NDVD_l simpfm_rl) -lemma rlfm_l: - assumes qfp: "qfree p" - shows "isrlfm (rlfm p)" - using qfp lt_l gt_l ge_l le_l eq_l neq_l DVD_l NDVD_l -by (induct p rule: rlfm.induct,auto simp add: simpfm_rl) - - (* Operations needed for Ferrante and Rackoff *) -lemma rminusinf_inf: - assumes lp: "isrlfm p" - shows "\ z. \ x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\ z. \ x. ?P z x p") -using lp -proof (induct p rule: minusinf.induct) - case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto -next - case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto -next - case (3 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (Eq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp - thus ?case by blast -next - case (4 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (NEq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp - thus ?case by blast -next - case (5 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Lt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp - thus ?case by blast -next - case (6 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Le (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Le (CN 0 c e))" by simp - thus ?case by blast -next - case (7 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Gt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp - thus ?case by blast -next - case (8 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Ge (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp - thus ?case by blast -qed simp_all - -lemma rplusinf_inf: - assumes lp: "isrlfm p" - shows "\ z. \ x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\ z. \ x. ?P z x p") -using lp -proof (induct p rule: isrlfm.induct) - case (1 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto -next - case (2 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto -next - case (3 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (Eq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp - thus ?case by blast -next - case (4 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (NEq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp - thus ?case by blast -next - case (5 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Lt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp - thus ?case by blast -next - case (6 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Le (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Le (CN 0 c e))" by simp - thus ?case by blast -next - case (7 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Gt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp - thus ?case by blast -next - case (8 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Ge (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp - thus ?case by blast -qed simp_all - -lemma rminusinf_bound0: - assumes lp: "isrlfm p" - shows "bound0 (minusinf p)" - using lp - by (induct p rule: minusinf.induct) simp_all - -lemma rplusinf_bound0: - assumes lp: "isrlfm p" - shows "bound0 (plusinf p)" - using lp - by (induct p rule: plusinf.induct) simp_all - -lemma rminusinf_ex: - assumes lp: "isrlfm p" - and ex: "Ifm (a#bs) (minusinf p)" - shows "\ x. Ifm (x#bs) p" -proof- - from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex - have th: "\ x. Ifm (x#bs) (minusinf p)" by auto - from rminusinf_inf[OF lp, where bs="bs"] - obtain z where z_def: "\x x. Ifm (x#bs) p" -proof- - from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex - have th: "\ x. Ifm (x#bs) (plusinf p)" by auto - from rplusinf_inf[OF lp, where bs="bs"] - obtain z where z_def: "\x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast - from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp - moreover have "z + 1 > z" by simp - ultimately show ?thesis using z_def by auto -qed - -consts - \:: "fm \ (num \ int) list" - \ :: "fm \ (num \ int) \ fm " -recdef \ "measure size" - "\ (And p q) = (\ p @ \ q)" - "\ (Or p q) = (\ p @ \ q)" - "\ (Eq (CN 0 c e)) = [(Neg e,c)]" - "\ (NEq (CN 0 c e)) = [(Neg e,c)]" - "\ (Lt (CN 0 c e)) = [(Neg e,c)]" - "\ (Le (CN 0 c e)) = [(Neg e,c)]" - "\ (Gt (CN 0 c e)) = [(Neg e,c)]" - "\ (Ge (CN 0 c e)) = [(Neg e,c)]" - "\ p = []" - -recdef \ "measure size" - "\ (And p q) = (\ (t,n). And (\ p (t,n)) (\ q (t,n)))" - "\ (Or p q) = (\ (t,n). Or (\ p (t,n)) (\ q (t,n)))" - "\ (Eq (CN 0 c e)) = (\ (t,n). Eq (Add (Mul c t) (Mul n e)))" - "\ (NEq (CN 0 c e)) = (\ (t,n). NEq (Add (Mul c t) (Mul n e)))" - "\ (Lt (CN 0 c e)) = (\ (t,n). Lt (Add (Mul c t) (Mul n e)))" - "\ (Le (CN 0 c e)) = (\ (t,n). Le (Add (Mul c t) (Mul n e)))" - "\ (Gt (CN 0 c e)) = (\ (t,n). Gt (Add (Mul c t) (Mul n e)))" - "\ (Ge (CN 0 c e)) = (\ (t,n). Ge (Add (Mul c t) (Mul n e)))" - "\ p = (\ (t,n). p)" - -lemma \_I: assumes lp: "isrlfm p" - and np: "real n > 0" and nbt: "numbound0 t" - shows "(Ifm (x#bs) (\ p (t,n)) = Ifm (((Inum (x#bs) t)/(real n))#bs) p) \ bound0 (\ p (t,n))" (is "(?I x (\ p (t,n)) = ?I ?u p) \ ?B p" is "(_ = ?I (?t/?n) p) \ _" is "(_ = ?I (?N x t /_) p) \ _") - using lp -proof(induct p rule: \.induct) - case (5 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Lt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) < 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)" - by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) < 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (6 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Le (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" - by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) \ 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (7 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Gt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) > 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)" - by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) > 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (8 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Ge (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" - by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) \ 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (3 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - from np have np: "real n \ 0" by simp - have "?I ?u (Eq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) = 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) = 0)" - by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) = 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (4 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - from np have np: "real n \ 0" by simp - have "?I ?u (NEq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" - by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) \ 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"] nth_pos2) - -lemma \_l: - assumes lp: "isrlfm p" - shows "\ (t,k) \ set (\ p). numbound0 t \ k >0" -using lp -by(induct p rule: \.induct) auto - -lemma rminusinf_\: - assumes lp: "isrlfm p" - and nmi: "\ (Ifm (a#bs) (minusinf p))" (is "\ (Ifm (a#bs) (?M p))") - and ex: "Ifm (x#bs) p" (is "?I x p") - shows "\ (s,m) \ set (\ p). x \ Inum (a#bs) s / real m" (is "\ (s,m) \ ?U p. x \ ?N a s / real m") -proof- - have "\ (s,m) \ set (\ p). real m * x \ Inum (a#bs) s " (is "\ (s,m) \ ?U p. real m *x \ ?N a s") - using lp nmi ex - by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2) - then obtain s m where smU: "(s,m) \ set (\ p)" and mx: "real m * x \ ?N a s" by blast - from \_l[OF lp] smU have mp: "real m > 0" by auto - from pos_divide_le_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \ ?N a s / real m" - by (auto simp add: mult_commute) - thus ?thesis using smU by auto -qed - -lemma rplusinf_\: - assumes lp: "isrlfm p" - and nmi: "\ (Ifm (a#bs) (plusinf p))" (is "\ (Ifm (a#bs) (?M p))") - and ex: "Ifm (x#bs) p" (is "?I x p") - shows "\ (s,m) \ set (\ p). x \ Inum (a#bs) s / real m" (is "\ (s,m) \ ?U p. x \ ?N a s / real m") -proof- - have "\ (s,m) \ set (\ p). real m * x \ Inum (a#bs) s " (is "\ (s,m) \ ?U p. real m *x \ ?N a s") - using lp nmi ex - by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2) - then obtain s m where smU: "(s,m) \ set (\ p)" and mx: "real m * x \ ?N a s" by blast - from \_l[OF lp] smU have mp: "real m > 0" by auto - from pos_le_divide_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \ ?N a s / real m" - by (auto simp add: mult_commute) - thus ?thesis using smU by auto -qed - -lemma lin_dense: - assumes lp: "isrlfm p" - and noS: "\ t. l < t \ t< u \ t \ (\ (t,n). Inum (x#bs) t / real n) ` set (\ p)" - (is "\ t. _ \ _ \ t \ (\ (t,n). ?N x t / real n ) ` (?U p)") - and lx: "l < x" and xu:"x < u" and px:" Ifm (x#bs) p" - and ly: "l < y" and yu: "y < u" - shows "Ifm (y#bs) p" -using lp px noS -proof (induct p rule: isrlfm.induct) - case (5 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from prems have "x * real c + ?N x e < 0" by (simp add: algebra_simps) - hence pxc: "x < (- ?N x e) / real c" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y < (-?N x e)/ real c" - hence "y * real c < - ?N x e" - by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y > (- ?N x e) / real c" - with yu have eu: "u > (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ l" by (cases "(- ?N x e) / real c > l", auto) - with lx pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (6 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp + - from prems have "x * real c + ?N x e \ 0" by (simp add: algebra_simps) - hence pxc: "x \ (- ?N x e) / real c" - by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y < (-?N x e)/ real c" - hence "y * real c < - ?N x e" - by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y > (- ?N x e) / real c" - with yu have eu: "u > (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ l" by (cases "(- ?N x e) / real c > l", auto) - with lx pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (7 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from prems have "x * real c + ?N x e > 0" by (simp add: algebra_simps) - hence pxc: "x > (- ?N x e) / real c" - by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y > (-?N x e)/ real c" - hence "y * real c > - ?N x e" - by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y < (- ?N x e) / real c" - with ly have eu: "l < (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ u" by (cases "(- ?N x e) / real c > l", auto) - with xu pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (8 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from prems have "x * real c + ?N x e \ 0" by (simp add: algebra_simps) - hence pxc: "x \ (- ?N x e) / real c" - by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y > (-?N x e)/ real c" - hence "y * real c > - ?N x e" - by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y < (- ?N x e) / real c" - with ly have eu: "l < (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ u" by (cases "(- ?N x e) / real c > l", auto) - with xu pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (3 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from cp have cnz: "real c \ 0" by simp - from prems have "x * real c + ?N x e = 0" by (simp add: algebra_simps) - hence pxc: "x = (- ?N x e) / real c" - by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with lx xu have yne: "x \ - ?N x e / real c" by auto - with pxc show ?case by simp -next - case (4 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from cp have cnz: "real c \ 0" by simp - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y* real c \ -?N x e" - by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp - hence "y* real c + ?N x e \ 0" by (simp add: algebra_simps) - thus ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] - by (simp add: algebra_simps) -qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="y" and b'="x"]) - -lemma finite_set_intervals: - assumes px: "P (x::real)" - and lx: "l \ x" and xu: "x \ u" - and linS: "l\ S" and uinS: "u \ S" - and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" - shows "\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a \ x \ x \ b \ P x" -proof- - let ?Mx = "{y. y\ S \ y \ x}" - let ?xM = "{y. y\ S \ x \ y}" - let ?a = "Max ?Mx" - let ?b = "Min ?xM" - have MxS: "?Mx \ S" by blast - hence fMx: "finite ?Mx" using fS finite_subset by auto - from lx linS have linMx: "l \ ?Mx" by blast - hence Mxne: "?Mx \ {}" by blast - have xMS: "?xM \ S" by blast - hence fxM: "finite ?xM" using fS finite_subset by auto - from xu uinS have linxM: "u \ ?xM" by blast - hence xMne: "?xM \ {}" by blast - have ax:"?a \ x" using Mxne fMx by auto - have xb:"x \ ?b" using xMne fxM by auto - have "?a \ ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \ S" using MxS by blast - have "?b \ ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \ S" using xMS by blast - have noy:"\ y. ?a < y \ y < ?b \ y \ S" - proof(clarsimp) - fix y - assume ay: "?a < y" and yb: "y < ?b" and yS: "y \ S" - from yS have "y\ ?Mx \ y\ ?xM" by auto - moreover {assume "y \ ?Mx" hence "y \ ?a" using Mxne fMx by auto with ay have "False" by simp} - moreover {assume "y \ ?xM" hence "y \ ?b" using xMne fxM by auto with yb have "False" by simp} - ultimately show "False" by blast - qed - from ainS binS noy ax xb px show ?thesis by blast -qed - -lemma finite_set_intervals2: - assumes px: "P (x::real)" - and lx: "l \ x" and xu: "x \ u" - and linS: "l\ S" and uinS: "u \ S" - and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" - shows "(\ s\ S. P s) \ (\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a < x \ x < b \ P x)" -proof- - from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su] - obtain a and b where - as: "a\ S" and bs: "b\ S" and noS:"\y. a < y \ y < b \ y \ S" and axb: "a \ x \ x \ b \ P x" by auto - from axb have "x= a \ x= b \ (a < x \ x < b)" by auto - thus ?thesis using px as bs noS by blast -qed - -lemma rinf_\: - assumes lp: "isrlfm p" - and nmi: "\ (Ifm (x#bs) (minusinf p))" (is "\ (Ifm (x#bs) (?M p))") - and npi: "\ (Ifm (x#bs) (plusinf p))" (is "\ (Ifm (x#bs) (?P p))") - and ex: "\ x. Ifm (x#bs) p" (is "\ x. ?I x p") - shows "\ (l,n) \ set (\ p). \ (s,m) \ set (\ p). ?I ((Inum (x#bs) l / real n + Inum (x#bs) s / real m) / 2) p" -proof- - let ?N = "\ x t. Inum (x#bs) t" - let ?U = "set (\ p)" - from ex obtain a where pa: "?I a p" by blast - from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi - have nmi': "\ (?I a (?M p))" by simp - from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi - have npi': "\ (?I a (?P p))" by simp - have "\ (l,n) \ set (\ p). \ (s,m) \ set (\ p). ?I ((?N a l/real n + ?N a s /real m) / 2) p" - proof- - let ?M = "(\ (t,c). ?N a t / real c) ` ?U" - have fM: "finite ?M" by auto - from rminusinf_\[OF lp nmi pa] rplusinf_\[OF lp npi pa] - have "\ (l,n) \ set (\ p). \ (s,m) \ set (\ p). a \ ?N x l / real n \ a \ ?N x s / real m" by blast - then obtain "t" "n" "s" "m" where - tnU: "(t,n) \ ?U" and smU: "(s,m) \ ?U" - and xs1: "a \ ?N x s / real m" and tx1: "a \ ?N x t / real n" by blast - from \_l[OF lp] tnU smU numbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 have xs: "a \ ?N a s / real m" and tx: "a \ ?N a t / real n" by auto - from tnU have Mne: "?M \ {}" by auto - hence Une: "?U \ {}" by simp - let ?l = "Min ?M" - let ?u = "Max ?M" - have linM: "?l \ ?M" using fM Mne by simp - have uinM: "?u \ ?M" using fM Mne by simp - have tnM: "?N a t / real n \ ?M" using tnU by auto - have smM: "?N a s / real m \ ?M" using smU by auto - have lM: "\ t\ ?M. ?l \ t" using Mne fM by auto - have Mu: "\ t\ ?M. t \ ?u" using Mne fM by auto - have "?l \ ?N a t / real n" using tnM Mne by simp hence lx: "?l \ a" using tx by simp - have "?N a s / real m \ ?u" using smM Mne by simp hence xu: "a \ ?u" using xs by simp - from finite_set_intervals2[where P="\ x. ?I x p",OF pa lx xu linM uinM fM lM Mu] - have "(\ s\ ?M. ?I s p) \ - (\ t1\ ?M. \ t2 \ ?M. (\ y. t1 < y \ y < t2 \ y \ ?M) \ t1 < a \ a < t2 \ ?I a p)" . - moreover { fix u assume um: "u\ ?M" and pu: "?I u p" - hence "\ (tu,nu) \ ?U. u = ?N a tu / real nu" by auto - then obtain "tu" "nu" where tuU: "(tu,nu) \ ?U" and tuu:"u= ?N a tu / real nu" by blast - have "(u + u) / 2 = u" by auto with pu tuu - have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" by simp - with tuU have ?thesis by blast} - moreover{ - assume "\ t1\ ?M. \ t2 \ ?M. (\ y. t1 < y \ y < t2 \ y \ ?M) \ t1 < a \ a < t2 \ ?I a p" - then obtain t1 and t2 where t1M: "t1 \ ?M" and t2M: "t2\ ?M" - and noM: "\ y. t1 < y \ y < t2 \ y \ ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p" - by blast - from t1M have "\ (t1u,t1n) \ ?U. t1 = ?N a t1u / real t1n" by auto - then obtain "t1u" "t1n" where t1uU: "(t1u,t1n) \ ?U" and t1u: "t1 = ?N a t1u / real t1n" by blast - from t2M have "\ (t2u,t2n) \ ?U. t2 = ?N a t2u / real t2n" by auto - then obtain "t2u" "t2n" where t2uU: "(t2u,t2n) \ ?U" and t2u: "t2 = ?N a t2u / real t2n" by blast - from t1x xt2 have t1t2: "t1 < t2" by simp - let ?u = "(t1 + t2) / 2" - from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto - from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" . - with t1uU t2uU t1u t2u have ?thesis by blast} - ultimately show ?thesis by blast - qed - then obtain "l" "n" "s" "m" where lnU: "(l,n) \ ?U" and smU:"(s,m) \ ?U" - and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" by blast - from lnU smU \_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" by auto - from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] - numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu - have "?I ((?N x l / real n + ?N x s / real m) / 2) p" by simp - with lnU smU - show ?thesis by auto -qed - (* The Ferrante - Rackoff Theorem *) - -theorem fr_eq: - assumes lp: "isrlfm p" - shows "(\ x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \ (Ifm (x#bs) (plusinf p)) \ (\ (t,n) \ set (\ p). \ (s,m) \ set (\ p). Ifm ((((Inum (x#bs) t)/ real n + (Inum (x#bs) s) / real m) /2)#bs) p))" - (is "(\ x. ?I x p) = (?M \ ?P \ ?F)" is "?E = ?D") -proof - assume px: "\ x. ?I x p" - have "?M \ ?P \ (\ ?M \ \ ?P)" by blast - moreover {assume "?M \ ?P" hence "?D" by blast} - moreover {assume nmi: "\ ?M" and npi: "\ ?P" - from rinf_\[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast} - ultimately show "?D" by blast -next - assume "?D" - moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} - moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } - moreover {assume f:"?F" hence "?E" by blast} - ultimately show "?E" by blast -qed - - -lemma fr_eq\: - assumes lp: "isrlfm p" - shows "(\ x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \ (Ifm (x#bs) (plusinf p)) \ (\ (t,k) \ set (\ p). \ (s,l) \ set (\ p). Ifm (x#bs) (\ p (Add(Mul l t) (Mul k s) , 2*k*l))))" - (is "(\ x. ?I x p) = (?M \ ?P \ ?F)" is "?E = ?D") -proof - assume px: "\ x. ?I x p" - have "?M \ ?P \ (\ ?M \ \ ?P)" by blast - moreover {assume "?M \ ?P" hence "?D" by blast} - moreover {assume nmi: "\ ?M" and npi: "\ ?P" - let ?f ="\ (t,n). Inum (x#bs) t / real n" - let ?N = "\ t. Inum (x#bs) t" - {fix t n s m assume "(t,n)\ set (\ p)" and "(s,m) \ set (\ p)" - with \_l[OF lp] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0" - by auto - let ?st = "Add (Mul m t) (Mul n s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute) - from tnb snb have st_nb: "numbound0 ?st" by simp - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mnp mp np by (simp add: algebra_simps add_divide_distrib) - from \_I[OF lp mnp st_nb, where x="x" and bs="bs"] - have "?I x (\ p (?st,2*n*m)) = ?I ((?N t / real n + ?N s / real m) /2) p" by (simp only: st[symmetric])} - with rinf_\[OF lp nmi npi px] have "?F" by blast hence "?D" by blast} - ultimately show "?D" by blast -next - assume "?D" - moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} - moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } - moreover {fix t k s l assume "(t,k) \ set (\ p)" and "(s,l) \ set (\ p)" - and px:"?I x (\ p (Add (Mul l t) (Mul k s), 2*k*l))" - with \_l[OF lp] have tnb: "numbound0 t" and np:"real k > 0" and snb: "numbound0 s" and mp:"real l > 0" by auto - let ?st = "Add (Mul l t) (Mul k s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*k*l) > 0" - by (simp add: mult_commute) - from tnb snb have st_nb: "numbound0 ?st" by simp - from \_I[OF lp mnp st_nb, where bs="bs"] px have "?E" by auto} - ultimately show "?E" by blast -qed - -text{* The overall Part *} - -lemma real_ex_int_real01: - shows "(\ (x::real). P x) = (\ (i::int) (u::real). 0\ u \ u< 1 \ P (real i + u))" -proof(auto) - fix x - assume Px: "P x" - let ?i = "floor x" - let ?u = "x - real ?i" - have "x = real ?i + ?u" by simp - hence "P (real ?i + ?u)" using Px by simp - moreover have "real ?i \ x" using real_of_int_floor_le by simp hence "0 \ ?u" by arith - moreover have "?u < 1" using real_of_int_floor_add_one_gt[where r="x"] by arith - ultimately show "(\ (i::int) (u::real). 0\ u \ u< 1 \ P (real i + u))" by blast -qed - -consts exsplitnum :: "num \ num" - exsplit :: "fm \ fm" -recdef exsplitnum "measure size" - "exsplitnum (C c) = (C c)" - "exsplitnum (Bound 0) = Add (Bound 0) (Bound 1)" - "exsplitnum (Bound n) = Bound (n+1)" - "exsplitnum (Neg a) = Neg (exsplitnum a)" - "exsplitnum (Add a b) = Add (exsplitnum a) (exsplitnum b) " - "exsplitnum (Sub a b) = Sub (exsplitnum a) (exsplitnum b) " - "exsplitnum (Mul c a) = Mul c (exsplitnum a)" - "exsplitnum (Floor a) = Floor (exsplitnum a)" - "exsplitnum (CN 0 c a) = CN 0 c (Add (Mul c (Bound 1)) (exsplitnum a))" - "exsplitnum (CN n c a) = CN (n+1) c (exsplitnum a)" - "exsplitnum (CF c s t) = CF c (exsplitnum s) (exsplitnum t)" - -recdef exsplit "measure size" - "exsplit (Lt a) = Lt (exsplitnum a)" - "exsplit (Le a) = Le (exsplitnum a)" - "exsplit (Gt a) = Gt (exsplitnum a)" - "exsplit (Ge a) = Ge (exsplitnum a)" - "exsplit (Eq a) = Eq (exsplitnum a)" - "exsplit (NEq a) = NEq (exsplitnum a)" - "exsplit (Dvd i a) = Dvd i (exsplitnum a)" - "exsplit (NDvd i a) = NDvd i (exsplitnum a)" - "exsplit (And p q) = And (exsplit p) (exsplit q)" - "exsplit (Or p q) = Or (exsplit p) (exsplit q)" - "exsplit (Imp p q) = Imp (exsplit p) (exsplit q)" - "exsplit (Iff p q) = Iff (exsplit p) (exsplit q)" - "exsplit (NOT p) = NOT (exsplit p)" - "exsplit p = p" - -lemma exsplitnum: - "Inum (x#y#bs) (exsplitnum t) = Inum ((x+y) #bs) t" - by(induct t rule: exsplitnum.induct) (simp_all add: algebra_simps) - -lemma exsplit: - assumes qfp: "qfree p" - shows "Ifm (x#y#bs) (exsplit p) = Ifm ((x+y)#bs) p" -using qfp exsplitnum[where x="x" and y="y" and bs="bs"] -by(induct p rule: exsplit.induct) simp_all - -lemma splitex: - assumes qf: "qfree p" - shows "(Ifm bs (E p)) = (\ (i::int). Ifm (real i#bs) (E (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) (exsplit p))))" (is "?lhs = ?rhs") -proof- - have "?rhs = (\ (i::int). \ x. 0\ x \ x < 1 \ Ifm (x#(real i)#bs) (exsplit p))" - by (simp add: myless[rule_format, where b="1"] myless[rule_format, where b="0"] add_ac diff_def) - also have "\ = (\ (i::int). \ x. 0\ x \ x < 1 \ Ifm ((real i + x) #bs) p)" - by (simp only: exsplit[OF qf] add_ac) - also have "\ = (\ x. Ifm (x#bs) p)" - by (simp only: real_ex_int_real01[where P="\ x. Ifm (x#bs) p"]) - finally show ?thesis by simp -qed - - (* Implement the right hand sides of Cooper's theorem and Ferrante and Rackoff. *) - -constdefs ferrack01:: "fm \ fm" - "ferrack01 p \ (let p' = rlfm(And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p); - U = remdups(map simp_num_pair - (map (\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) - (alluopairs (\ p')))) - in decr (evaldjf (\ p') U ))" - -lemma fr_eq_01: - assumes qf: "qfree p" - shows "(\ x. Ifm (x#bs) (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)) = (\ (t,n) \ set (\ (rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p))). \ (s,m) \ set (\ (rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p))). Ifm (x#bs) (\ (rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)) (Add (Mul m t) (Mul n s), 2*n*m)))" - (is "(\ x. ?I x ?q) = ?F") -proof- - let ?rq = "rlfm ?q" - let ?M = "?I x (minusinf ?rq)" - let ?P = "?I x (plusinf ?rq)" - have MF: "?M = False" - apply (simp add: Let_def reducecoeff_def numgcd_def zgcd_def rsplit_def ge_def lt_def conj_def disj_def) - by (cases "rlfm p = And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C -1)))", simp_all) - have PF: "?P = False" apply (simp add: Let_def reducecoeff_def numgcd_def zgcd_def rsplit_def ge_def lt_def conj_def disj_def) - by (cases "rlfm p = And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C -1)))", simp_all) - have "(\ x. ?I x ?q ) = - ((?I x (minusinf ?rq)) \ (?I x (plusinf ?rq )) \ (\ (t,n) \ set (\ ?rq). \ (s,m) \ set (\ ?rq ). ?I x (\ ?rq (Add (Mul m t) (Mul n s), 2*n*m))))" - (is "(\ x. ?I x ?q) = (?M \ ?P \ ?F)" is "?E = ?D") - proof - assume "\ x. ?I x ?q" - then obtain x where qx: "?I x ?q" by blast - hence xp: "0\ x" and x1: "x< 1" and px: "?I x p" - by (auto simp add: rsplit_def lt_def ge_def rlfm_I[OF qf]) - from qx have "?I x ?rq " - by (simp add: rsplit_def lt_def ge_def rlfm_I[OF qf xp x1]) - hence lqx: "?I x ?rq " using simpfm[where p="?rq" and bs="x#bs"] by auto - from qf have qfq:"isrlfm ?rq" - by (auto simp add: rsplit_def lt_def ge_def rlfm_I[OF qf xp x1]) - with lqx fr_eq\[OF qfq] show "?M \ ?P \ ?F" by blast - next - assume D: "?D" - let ?U = "set (\ ?rq )" - from MF PF D have "?F" by auto - then obtain t n s m where aU:"(t,n) \ ?U" and bU:"(s,m)\ ?U" and rqx: "?I x (\ ?rq (Add (Mul m t) (Mul n s), 2*n*m))" by blast - from qf have lrq:"isrlfm ?rq"using rlfm_l[OF qf] - by (auto simp add: rsplit_def lt_def ge_def) - from aU bU \_l[OF lrq] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0" by (auto simp add: split_def) - let ?st = "Add (Mul m t) (Mul n s)" - from tnb snb have stnb: "numbound0 ?st" by simp - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute) - from conjunct1[OF \_I[OF lrq mnp stnb, where bs="bs" and x="x"], symmetric] rqx - have "\ x. ?I x ?rq" by auto - thus "?E" - using rlfm_I[OF qf] by (auto simp add: rsplit_def lt_def ge_def) - qed - with MF PF show ?thesis by blast -qed - -lemma \_cong_aux: - assumes Ul: "\ (t,n) \ set U. numbound0 t \ n >0" - shows "((\ (t,n). Inum (x#bs) t /real n) ` (set (map (\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) (alluopairs U)))) = ((\ ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (set U \ set U))" - (is "?lhs = ?rhs") -proof(auto) - fix t n s m - assume "((t,n),(s,m)) \ set (alluopairs U)" - hence th: "((t,n),(s,m)) \ (set U \ set U)" - using alluopairs_set1[where xs="U"] by blast - let ?N = "\ t. Inum (x#bs) t" - let ?st= "Add (Mul m t) (Mul n s)" - from Ul th have mnz: "m \ 0" by auto - from Ul th have nnz: "n \ 0" by auto - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mnz nnz by (simp add: algebra_simps add_divide_distrib) - - thus "(real m * Inum (x # bs) t + real n * Inum (x # bs) s) / - (2 * real n * real m) - \ (\((t, n), s, m). - (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` - (set U \ set U)"using mnz nnz th - apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def) - by (rule_tac x="(s,m)" in bexI,simp_all) - (rule_tac x="(t,n)" in bexI,simp_all) -next - fix t n s m - assume tnU: "(t,n) \ set U" and smU:"(s,m) \ set U" - let ?N = "\ t. Inum (x#bs) t" - let ?st= "Add (Mul m t) (Mul n s)" - from Ul smU have mnz: "m \ 0" by auto - from Ul tnU have nnz: "n \ 0" by auto - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mnz nnz by (simp add: algebra_simps add_divide_distrib) - let ?P = "\ (t',n') (s',m'). (Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" - have Pc:"\ a b. ?P a b = ?P b a" - by auto - from Ul alluopairs_set1 have Up:"\ ((t,n),(s,m)) \ set (alluopairs U). n \ 0 \ m \ 0" by blast - from alluopairs_ex[OF Pc, where xs="U"] tnU smU - have th':"\ ((t',n'),(s',m')) \ set (alluopairs U). ?P (t',n') (s',m')" - by blast - then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \ set (alluopairs U)" - and Pts': "?P (t',n') (s',m')" by blast - from ts'_U Up have mnz': "m' \ 0" and nnz': "n'\ 0" by auto - let ?st' = "Add (Mul m' t') (Mul n' s')" - have st': "(?N t' / real n' + ?N s' / real m')/2 = ?N ?st' / real (2*n'*m')" - using mnz' nnz' by (simp add: algebra_simps add_divide_distrib) - from Pts' have - "(Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" by simp - also have "\ = ((\(t, n). Inum (x # bs) t / real n) ((\((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ((t',n'),(s',m'))))" by (simp add: st') - finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2 - \ (\(t, n). Inum (x # bs) t / real n) ` - (\((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ` - set (alluopairs U)" - using ts'_U by blast -qed - -lemma \_cong: - assumes lp: "isrlfm p" - and UU': "((\ (t,n). Inum (x#bs) t /real n) ` U') = ((\ ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (U \ U))" (is "?f ` U' = ?g ` (U\U)") - and U: "\ (t,n) \ U. numbound0 t \ n > 0" - and U': "\ (t,n) \ U'. numbound0 t \ n > 0" - shows "(\ (t,n) \ U. \ (s,m) \ U. Ifm (x#bs) (\ p (Add (Mul m t) (Mul n s),2*n*m))) = (\ (t,n) \ U'. Ifm (x#bs) (\ p (t,n)))" - (is "?lhs = ?rhs") -proof - assume ?lhs - then obtain t n s m where tnU: "(t,n) \ U" and smU:"(s,m) \ U" and - Pst: "Ifm (x#bs) (\ p (Add (Mul m t) (Mul n s),2*n*m))" by blast - let ?N = "\ t. Inum (x#bs) t" - from tnU smU U have tnb: "numbound0 t" and np: "n > 0" - and snb: "numbound0 s" and mp:"m > 0" by auto - let ?st= "Add (Mul m t) (Mul n s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) - from tnb snb have stnb: "numbound0 ?st" by simp - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mp np by (simp add: algebra_simps add_divide_distrib) - from tnU smU UU' have "?g ((t,n),(s,m)) \ ?f ` U'" by blast - hence "\ (t',n') \ U'. ?g ((t,n),(s,m)) = ?f (t',n')" - by auto (rule_tac x="(a,b)" in bexI, auto) - then obtain t' n' where tnU': "(t',n') \ U'" and th: "?g ((t,n),(s,m)) = ?f (t',n')" by blast - from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto - from \_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst - have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp - from conjunct1[OF \_I[OF lp np' tnb', where bs="bs" and x="x"], symmetric] th[simplified split_def fst_conv snd_conv,symmetric] Pst2[simplified st[symmetric]] - have "Ifm (x # bs) (\ p (t', n')) " by (simp only: st) - then show ?rhs using tnU' by auto -next - assume ?rhs - then obtain t' n' where tnU': "(t',n') \ U'" and Pt': "Ifm (x # bs) (\ p (t', n'))" - by blast - from tnU' UU' have "?f (t',n') \ ?g ` (U\U)" by blast - hence "\ ((t,n),(s,m)) \ (U\U). ?f (t',n') = ?g ((t,n),(s,m))" - by auto (rule_tac x="(a,b)" in bexI, auto) - then obtain t n s m where tnU: "(t,n) \ U" and smU:"(s,m) \ U" and - th: "?f (t',n') = ?g((t,n),(s,m)) "by blast - let ?N = "\ t. Inum (x#bs) t" - from tnU smU U have tnb: "numbound0 t" and np: "n > 0" - and snb: "numbound0 s" and mp:"m > 0" by auto - let ?st= "Add (Mul m t) (Mul n s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) - from tnb snb have stnb: "numbound0 ?st" by simp - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mp np by (simp add: algebra_simps add_divide_distrib) - from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto - from \_I[OF lp np' tnb', where bs="bs" and x="x",simplified th[simplified split_def fst_conv snd_conv] st] Pt' - have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp - with \_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU show ?lhs by blast -qed - -lemma ferrack01: - assumes qf: "qfree p" - shows "((\ x. Ifm (x#bs) (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)) = (Ifm bs (ferrack01 p))) \ qfree (ferrack01 p)" (is "(?lhs = ?rhs) \ _") -proof- - let ?I = "\ x p. Ifm (x#bs) p" - fix x - let ?N = "\ t. Inum (x#bs) t" - let ?q = "rlfm (And (And (Ge(CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) p)" - let ?U = "\ ?q" - let ?Up = "alluopairs ?U" - let ?g = "\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)" - let ?S = "map ?g ?Up" - let ?SS = "map simp_num_pair ?S" - let ?Y = "remdups ?SS" - let ?f= "(\ (t,n). ?N t / real n)" - let ?h = "\ ((t,n),(s,m)). (?N t/real n + ?N s/ real m) /2" - let ?F = "\ p. \ a \ set (\ p). \ b \ set (\ p). ?I x (\ p (?g(a,b)))" - let ?ep = "evaldjf (\ ?q) ?Y" - from rlfm_l[OF qf] have lq: "isrlfm ?q" - by (simp add: rsplit_def lt_def ge_def conj_def disj_def Let_def reducecoeff_def numgcd_def zgcd_def) - from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \ (set ?U \ set ?U)" by simp - from \_l[OF lq] have U_l: "\ (t,n) \ set ?U. numbound0 t \ n > 0" . - from U_l UpU - have Up_: "\ ((t,n),(s,m)) \ set ?Up. numbound0 t \ n> 0 \ numbound0 s \ m > 0" by auto - hence Snb: "\ (t,n) \ set ?S. numbound0 t \ n > 0 " - by (auto simp add: mult_pos_pos) - have Y_l: "\ (t,n) \ set ?Y. numbound0 t \ n > 0" - proof- - { fix t n assume tnY: "(t,n) \ set ?Y" - hence "(t,n) \ set ?SS" by simp - hence "\ (t',n') \ set ?S. simp_num_pair (t',n') = (t,n)" - by (auto simp add: split_def) (rule_tac x="((aa,ba),(ab,bb))" in bexI, simp_all) - then obtain t' n' where tn'S: "(t',n') \ set ?S" and tns: "simp_num_pair (t',n') = (t,n)" by blast - from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" by auto - from simp_num_pair_l[OF tnb np tns] - have "numbound0 t \ n > 0" . } - thus ?thesis by blast - qed - - have YU: "(?f ` set ?Y) = (?h ` (set ?U \ set ?U))" - proof- - from simp_num_pair_ci[where bs="x#bs"] have - "\x. (?f o simp_num_pair) x = ?f x" by auto - hence th: "?f o simp_num_pair = ?f" using ext by blast - have "(?f ` set ?Y) = ((?f o simp_num_pair) ` set ?S)" by (simp add: image_compose) - also have "\ = (?f ` set ?S)" by (simp add: th) - also have "\ = ((?f o ?g) ` set ?Up)" - by (simp only: set_map o_def image_compose[symmetric]) - also have "\ = (?h ` (set ?U \ set ?U))" - using \_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_compose[symmetric]] by blast - finally show ?thesis . - qed - have "\ (t,n) \ set ?Y. bound0 (\ ?q (t,n))" - proof- - { fix t n assume tnY: "(t,n) \ set ?Y" - with Y_l have tnb: "numbound0 t" and np: "real n > 0" by auto - from \_I[OF lq np tnb] - have "bound0 (\ ?q (t,n))" by simp} - thus ?thesis by blast - qed - hence ep_nb: "bound0 ?ep" using evaldjf_bound0[where xs="?Y" and f="\ ?q"] - by auto - - from fr_eq_01[OF qf, where bs="bs" and x="x"] have "?lhs = ?F ?q" - by (simp only: split_def fst_conv snd_conv) - also have "\ = (\ (t,n) \ set ?Y. ?I x (\ ?q (t,n)))" using \_cong[OF lq YU U_l Y_l] - by (simp only: split_def fst_conv snd_conv) - also have "\ = (Ifm (x#bs) ?ep)" - using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="\ ?q",symmetric] - by (simp only: split_def pair_collapse) - also have "\ = (Ifm bs (decr ?ep))" using decr[OF ep_nb] by blast - finally have lr: "?lhs = ?rhs" by (simp only: ferrack01_def Let_def) - from decr_qf[OF ep_nb] have "qfree (ferrack01 p)" by (simp only: Let_def ferrack01_def) - with lr show ?thesis by blast -qed - -lemma cp_thm': - assumes lp: "iszlfm p (real (i::int)#bs)" - and up: "d\ p 1" and dd: "d\ p d" and dp: "d > 0" - shows "(\ (x::int). Ifm (real x#bs) p) = ((\ j\ {1 .. d}. Ifm (real j#bs) (minusinf p)) \ (\ j\ {1.. d}. \ b\ (Inum (real i#bs)) ` set (\ p). Ifm ((b+real j)#bs) p))" - using cp_thm[OF lp up dd dp] by auto - -constdefs unit:: "fm \ fm \ num list \ int" - "unit p \ (let p' = zlfm p ; l = \ p' ; q = And (Dvd l (CN 0 1 (C 0))) (a\ p' l); d = \ q; - B = remdups (map simpnum (\ q)) ; a = remdups (map simpnum (\ q)) - in if length B \ length a then (q,B,d) else (mirror q, a,d))" - -lemma unit: assumes qf: "qfree p" - shows "\ q B d. unit p = (q,B,d) \ ((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ (Inum (real i#bs)) ` set B = (Inum (real i#bs)) ` set (\ q) \ d\ q 1 \ d\ q d \ d >0 \ iszlfm q (real (i::int)#bs) \ (\ b\ set B. numbound0 b)" -proof- - fix q B d - assume qBd: "unit p = (q,B,d)" - let ?thes = "((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ - Inum (real i#bs) ` set B = Inum (real i#bs) ` set (\ q) \ - d\ q 1 \ d\ q d \ 0 < d \ iszlfm q (real i # bs) \ (\ b\ set B. numbound0 b)" - let ?I = "\ (x::int) p. Ifm (real x#bs) p" - let ?p' = "zlfm p" - let ?l = "\ ?p'" - let ?q = "And (Dvd ?l (CN 0 1 (C 0))) (a\ ?p' ?l)" - let ?d = "\ ?q" - let ?B = "set (\ ?q)" - let ?B'= "remdups (map simpnum (\ ?q))" - let ?A = "set (\ ?q)" - let ?A'= "remdups (map simpnum (\ ?q))" - from conjunct1[OF zlfm_I[OF qf, where bs="bs"]] - have pp': "\ i. ?I i ?p' = ?I i p" by auto - from iszlfm_gen[OF conjunct2[OF zlfm_I[OF qf, where bs="bs" and i="i"]]] - have lp': "\ (i::int). iszlfm ?p' (real i#bs)" by simp - hence lp'': "iszlfm ?p' (real (i::int)#bs)" by simp - from lp' \[where p="?p'" and bs="bs"] have lp: "?l >0" and dl: "d\ ?p' ?l" by auto - from a\_ex[where p="?p'" and l="?l" and bs="bs", OF lp'' dl lp] pp' - have pq_ex:"(\ (x::int). ?I x p) = (\ x. ?I x ?q)" by (simp add: int_rdvd_iff) - from lp'' lp a\[OF lp'' dl lp] have lq:"iszlfm ?q (real i#bs)" and uq: "d\ ?q 1" - by (auto simp add: isint_def) - from \[OF lq] have dp:"?d >0" and dd: "d\ ?q ?d" by blast+ - let ?N = "\ t. Inum (real (i::int)#bs) t" - have "?N ` set ?B' = ((?N o simpnum) ` ?B)" by (simp add:image_compose) - also have "\ = ?N ` ?B" using simpnum_ci[where bs="real i #bs"] by auto - finally have BB': "?N ` set ?B' = ?N ` ?B" . - have "?N ` set ?A' = ((?N o simpnum) ` ?A)" by (simp add:image_compose) - also have "\ = ?N ` ?A" using simpnum_ci[where bs="real i #bs"] by auto - finally have AA': "?N ` set ?A' = ?N ` ?A" . - from \_numbound0[OF lq] have B_nb:"\ b\ set ?B'. numbound0 b" - by (simp add: simpnum_numbound0) - from \_l[OF lq] have A_nb: "\ b\ set ?A'. numbound0 b" - by (simp add: simpnum_numbound0) - {assume "length ?B' \ length ?A'" - hence q:"q=?q" and "B = ?B'" and d:"d = ?d" - using qBd by (auto simp add: Let_def unit_def) - with BB' B_nb have b: "?N ` (set B) = ?N ` set (\ q)" - and bn: "\b\ set B. numbound0 b" by simp+ - with pq_ex dp uq dd lq q d have ?thes by simp} - moreover - {assume "\ (length ?B' \ length ?A')" - hence q:"q=mirror ?q" and "B = ?A'" and d:"d = ?d" - using qBd by (auto simp add: Let_def unit_def) - with AA' mirror\\[OF lq] A_nb have b:"?N ` (set B) = ?N ` set (\ q)" - and bn: "\b\ set B. numbound0 b" by simp+ - from mirror_ex[OF lq] pq_ex q - have pqm_eq:"(\ (x::int). ?I x p) = (\ (x::int). ?I x q)" by simp - from lq uq q mirror_d\ [where p="?q" and bs="bs" and a="real i"] - have lq': "iszlfm q (real i#bs)" and uq: "d\ q 1" by auto - from \[OF lq'] mirror_\[OF lq] q d have dq:"d\ q d " by auto - from pqm_eq b bn uq lq' dp dq q dp d have ?thes by simp - } - ultimately show ?thes by blast -qed - (* Cooper's Algorithm *) - -constdefs cooper :: "fm \ fm" - "cooper p \ - (let (q,B,d) = unit p; js = iupt (1,d); - mq = simpfm (minusinf q); - md = evaldjf (\ j. simpfm (subst0 (C j) mq)) js - in if md = T then T else - (let qd = evaldjf (\ t. simpfm (subst0 t q)) - (remdups (map (\ (b,j). simpnum (Add b (C j))) - [(b,j). b\B,j\js])) - in decr (disj md qd)))" -lemma cooper: assumes qf: "qfree p" - shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (cooper p))) \ qfree (cooper p)" - (is "(?lhs = ?rhs) \ _") -proof- - - let ?I = "\ (x::int) p. Ifm (real x#bs) p" - let ?q = "fst (unit p)" - let ?B = "fst (snd(unit p))" - let ?d = "snd (snd (unit p))" - let ?js = "iupt (1,?d)" - let ?mq = "minusinf ?q" - let ?smq = "simpfm ?mq" - let ?md = "evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js" - fix i - let ?N = "\ t. Inum (real (i::int)#bs) t" - let ?bjs = "[(b,j). b\?B,j\?js]" - let ?sbjs = "map (\ (b,j). simpnum (Add b (C j))) ?bjs" - let ?qd = "evaldjf (\ t. simpfm (subst0 t ?q)) (remdups ?sbjs)" - have qbf:"unit p = (?q,?B,?d)" by simp - from unit[OF qf qbf] have pq_ex: "(\(x::int). ?I x p) = (\ (x::int). ?I x ?q)" and - B:"?N ` set ?B = ?N ` set (\ ?q)" and - uq:"d\ ?q 1" and dd: "d\ ?q ?d" and dp: "?d > 0" and - lq: "iszlfm ?q (real i#bs)" and - Bn: "\ b\ set ?B. numbound0 b" by auto - from zlin_qfree[OF lq] have qfq: "qfree ?q" . - from simpfm_qf[OF minusinf_qfree[OF qfq]] have qfmq: "qfree ?smq". - have jsnb: "\ j \ set ?js. numbound0 (C j)" by simp - hence "\ j\ set ?js. bound0 (subst0 (C j) ?smq)" - by (auto simp only: subst0_bound0[OF qfmq]) - hence th: "\ j\ set ?js. bound0 (simpfm (subst0 (C j) ?smq))" - by (auto simp add: simpfm_bound0) - from evaldjf_bound0[OF th] have mdb: "bound0 ?md" by simp - from Bn jsnb have "\ (b,j) \ set ?bjs. numbound0 (Add b (C j))" - by simp - hence "\ (b,j) \ set ?bjs. numbound0 (simpnum (Add b (C j)))" - using simpnum_numbound0 by blast - hence "\ t \ set ?sbjs. numbound0 t" by simp - hence "\ t \ set (remdups ?sbjs). bound0 (subst0 t ?q)" - using subst0_bound0[OF qfq] by auto - hence th': "\ t \ set (remdups ?sbjs). bound0 (simpfm (subst0 t ?q))" - using simpfm_bound0 by blast - from evaldjf_bound0 [OF th'] have qdb: "bound0 ?qd" by simp - from mdb qdb - have mdqdb: "bound0 (disj ?md ?qd)" by (simp only: disj_def, cases "?md=T \ ?qd=T", simp_all) - from trans [OF pq_ex cp_thm'[OF lq uq dd dp]] B - have "?lhs = (\ j\ {1.. ?d}. ?I j ?mq \ (\ b\ ?N ` set ?B. Ifm ((b+ real j)#bs) ?q))" by auto - also have "\ = ((\ j\ set ?js. ?I j ?smq) \ (\ (b,j) \ (?N ` set ?B \ set ?js). Ifm ((b+ real j)#bs) ?q))" apply (simp only: iupt_set simpfm) by auto - also have "\= ((\ j\ set ?js. ?I j ?smq) \ (\ t \ (\ (b,j). ?N (Add b (C j))) ` set ?bjs. Ifm (t #bs) ?q))" by simp - also have "\= ((\ j\ set ?js. ?I j ?smq) \ (\ t \ (\ (b,j). ?N (simpnum (Add b (C j)))) ` set ?bjs. Ifm (t #bs) ?q))" by (simp only: simpnum_ci) - also have "\= ((\ j\ set ?js. ?I j ?smq) \ (\ t \ set ?sbjs. Ifm (?N t #bs) ?q))" - by (auto simp add: split_def) - also have "\ = ((\ j\ set ?js. (\ j. ?I i (simpfm (subst0 (C j) ?smq))) j) \ (\ t \ set (remdups ?sbjs). (\ t. ?I i (simpfm (subst0 t ?q))) t))" by (simp only: simpfm subst0_I[OF qfq] simpfm Inum.simps subst0_I[OF qfmq] set_remdups) - also have "\ = ((?I i (evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js)) \ (?I i (evaldjf (\ t. simpfm (subst0 t ?q)) (remdups ?sbjs))))" by (simp only: evaldjf_ex) - finally have mdqd: "?lhs = (?I i (disj ?md ?qd))" by (simp add: disj) - hence mdqd2: "?lhs = (Ifm bs (decr (disj ?md ?qd)))" using decr [OF mdqdb] by simp - {assume mdT: "?md = T" - hence cT:"cooper p = T" - by (simp only: cooper_def unit_def split_def Let_def if_True) simp - from mdT mdqd have lhs:"?lhs" by (auto simp add: disj) - from mdT have "?rhs" by (simp add: cooper_def unit_def split_def) - with lhs cT have ?thesis by simp } - moreover - {assume mdT: "?md \ T" hence "cooper p = decr (disj ?md ?qd)" - by (simp only: cooper_def unit_def split_def Let_def if_False) - with mdqd2 decr_qf[OF mdqdb] have ?thesis by simp } - ultimately show ?thesis by blast -qed - -lemma DJcooper: - assumes qf: "qfree p" - shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (DJ cooper p))) \ qfree (DJ cooper p)" -proof- - from cooper have cqf: "\ p. qfree p \ qfree (cooper p)" by blast - from DJ_qf[OF cqf] qf have thqf:"qfree (DJ cooper p)" by blast - have "Ifm bs (DJ cooper p) = (\ q\ set (disjuncts p). Ifm bs (cooper q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = (\ q \ set(disjuncts p). \ (x::int). Ifm (real x#bs) q)" - using cooper disjuncts_qf[OF qf] by blast - also have "\ = (\ (x::int). Ifm (real x#bs) p)" by (induct p rule: disjuncts.induct, auto) - finally show ?thesis using thqf by blast -qed - - (* Redy and Loveland *) - -lemma \\_cong: assumes lp: "iszlfm p (a#bs)" and tt': "Inum (a#bs) t = Inum (a#bs) t'" - shows "Ifm (a#bs) (\\ p (t,c)) = Ifm (a#bs) (\\ p (t',c))" - using lp - by (induct p rule: iszlfm.induct, auto simp add: tt') - -lemma \_cong: assumes lp: "iszlfm p (a#bs)" and tt': "Inum (a#bs) t = Inum (a#bs) t'" - shows "Ifm (a#bs) (\ p c t) = Ifm (a#bs) (\ p c t')" - by (simp add: \_def tt' \\_cong[OF lp tt']) - -lemma \_cong: assumes lp: "iszlfm p (a#bs)" - and RR: "(\(b,k). (Inum (a#bs) b,k)) ` R = (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" - shows "(\ (e,c) \ R. \ j\ {1.. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j)))) = (\ (e,c) \ set (\ p). \ j\ {1.. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j))))" - (is "?lhs = ?rhs") -proof - let ?d = "\ p" - assume ?lhs then obtain e c j where ecR: "(e,c) \ R" and jD:"j \ {1 .. c*?d}" - and px: "Ifm (a#bs) (\ p c (Add e (C j)))" (is "?sp c e j") by blast - from ecR have "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` R" by auto - hence "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" using RR by simp - hence "\ (e',c') \ set (\ p). Inum (a#bs) e = Inum (a#bs) e' \ c = c'" by auto - then obtain e' c' where ecRo:"(e',c') \ set (\ p)" and ee':"Inum (a#bs) e = Inum (a#bs) e'" - and cc':"c = c'" by blast - from ee' have tt': "Inum (a#bs) (Add e (C j)) = Inum (a#bs) (Add e' (C j))" by simp - - from \_cong[OF lp tt', where c="c"] px have px':"?sp c e' j" by simp - from ecRo jD px' cc' show ?rhs apply auto - by (rule_tac x="(e', c')" in bexI,simp_all) - (rule_tac x="j" in bexI, simp_all add: cc'[symmetric]) -next - let ?d = "\ p" - assume ?rhs then obtain e c j where ecR: "(e,c) \ set (\ p)" and jD:"j \ {1 .. c*?d}" - and px: "Ifm (a#bs) (\ p c (Add e (C j)))" (is "?sp c e j") by blast - from ecR have "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" by auto - hence "(Inum (a#bs) e,c) \ (\(b,k). (Inum (a#bs) b,k)) ` R" using RR by simp - hence "\ (e',c') \ R. Inum (a#bs) e = Inum (a#bs) e' \ c = c'" by auto - then obtain e' c' where ecRo:"(e',c') \ R" and ee':"Inum (a#bs) e = Inum (a#bs) e'" - and cc':"c = c'" by blast - from ee' have tt': "Inum (a#bs) (Add e (C j)) = Inum (a#bs) (Add e' (C j))" by simp - from \_cong[OF lp tt', where c="c"] px have px':"?sp c e' j" by simp - from ecRo jD px' cc' show ?lhs apply auto - by (rule_tac x="(e', c')" in bexI,simp_all) - (rule_tac x="j" in bexI, simp_all add: cc'[symmetric]) -qed - -lemma rl_thm': - assumes lp: "iszlfm p (real (i::int)#bs)" - and R: "(\(b,k). (Inum (a#bs) b,k)) ` R = (\(b,k). (Inum (a#bs) b,k)) ` set (\ p)" - shows "(\ (x::int). Ifm (real x#bs) p) = ((\ j\ {1 .. \ p}. Ifm (real j#bs) (minusinf p)) \ (\ (e,c) \ R. \ j\ {1.. c*(\ p)}. Ifm (a#bs) (\ p c (Add e (C j)))))" - using rl_thm[OF lp] \_cong[OF iszlfm_gen[OF lp, rule_format, where y="a"] R] by simp - -constdefs chooset:: "fm \ fm \ ((num\int) list) \ int" - "chooset p \ (let q = zlfm p ; d = \ q; - B = remdups (map (\ (t,k). (simpnum t,k)) (\ q)) ; - a = remdups (map (\ (t,k). (simpnum t,k)) (\\ q)) - in if length B \ length a then (q,B,d) else (mirror q, a,d))" - -lemma chooset: assumes qf: "qfree p" - shows "\ q B d. chooset p = (q,B,d) \ ((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ ((\(t,k). (Inum (real i#bs) t,k)) ` set B = (\(t,k). (Inum (real i#bs) t,k)) ` set (\ q)) \ (\ q = d) \ d >0 \ iszlfm q (real (i::int)#bs) \ (\ (e,c)\ set B. numbound0 e \ c>0)" -proof- - fix q B d - assume qBd: "chooset p = (q,B,d)" - let ?thes = "((\ (x::int). Ifm (real x#bs) p) = (\ (x::int). Ifm (real x#bs) q)) \ ((\(t,k). (Inum (real i#bs) t,k)) ` set B = (\(t,k). (Inum (real i#bs) t,k)) ` set (\ q)) \ (\ q = d) \ d >0 \ iszlfm q (real (i::int)#bs) \ (\ (e,c)\ set B. numbound0 e \ c>0)" - let ?I = "\ (x::int) p. Ifm (real x#bs) p" - let ?q = "zlfm p" - let ?d = "\ ?q" - let ?B = "set (\ ?q)" - let ?f = "\ (t,k). (simpnum t,k)" - let ?B'= "remdups (map ?f (\ ?q))" - let ?A = "set (\\ ?q)" - let ?A'= "remdups (map ?f (\\ ?q))" - from conjunct1[OF zlfm_I[OF qf, where bs="bs"]] - have pp': "\ i. ?I i ?q = ?I i p" by auto - hence pq_ex:"(\ (x::int). ?I x p) = (\ x. ?I x ?q)" by simp - from iszlfm_gen[OF conjunct2[OF zlfm_I[OF qf, where bs="bs" and i="i"]], rule_format, where y="real i"] - have lq: "iszlfm ?q (real (i::int)#bs)" . - from \[OF lq] have dp:"?d >0" by blast - let ?N = "\ (t,c). (Inum (real (i::int)#bs) t,c)" - have "?N ` set ?B' = ((?N o ?f) ` ?B)" by (simp add: split_def image_compose) - also have "\ = ?N ` ?B" - by(simp add: split_def image_compose simpnum_ci[where bs="real i #bs"] image_def) - finally have BB': "?N ` set ?B' = ?N ` ?B" . - have "?N ` set ?A' = ((?N o ?f) ` ?A)" by (simp add: split_def image_compose) - also have "\ = ?N ` ?A" using simpnum_ci[where bs="real i #bs"] - by(simp add: split_def image_compose simpnum_ci[where bs="real i #bs"] image_def) - finally have AA': "?N ` set ?A' = ?N ` ?A" . - from \_l[OF lq] have B_nb:"\ (e,c)\ set ?B'. numbound0 e \ c > 0" - by (simp add: simpnum_numbound0 split_def) - from \\_l[OF lq] have A_nb: "\ (e,c)\ set ?A'. numbound0 e \ c > 0" - by (simp add: simpnum_numbound0 split_def) - {assume "length ?B' \ length ?A'" - hence q:"q=?q" and "B = ?B'" and d:"d = ?d" - using qBd by (auto simp add: Let_def chooset_def) - with BB' B_nb have b: "?N ` (set B) = ?N ` set (\ q)" - and bn: "\(e,c)\ set B. numbound0 e \ c > 0" by auto - with pq_ex dp lq q d have ?thes by simp} - moreover - {assume "\ (length ?B' \ length ?A')" - hence q:"q=mirror ?q" and "B = ?A'" and d:"d = ?d" - using qBd by (auto simp add: Let_def chooset_def) - with AA' mirror_\\[OF lq] A_nb have b:"?N ` (set B) = ?N ` set (\ q)" - and bn: "\(e,c)\ set B. numbound0 e \ c > 0" by auto - from mirror_ex[OF lq] pq_ex q - have pqm_eq:"(\ (x::int). ?I x p) = (\ (x::int). ?I x q)" by simp - from lq q mirror_l [where p="?q" and bs="bs" and a="real i"] - have lq': "iszlfm q (real i#bs)" by auto - from mirror_\[OF lq] pqm_eq b bn lq' dp q dp d have ?thes by simp - } - ultimately show ?thes by blast -qed - -constdefs stage:: "fm \ int \ (num \ int) \ fm" - "stage p d \ (\ (e,c). evaldjf (\ j. simpfm (\ p c (Add e (C j)))) (iupt (1,c*d)))" -lemma stage: - shows "Ifm bs (stage p d (e,c)) = (\ j\{1 .. c*d}. Ifm bs (\ p c (Add e (C j))))" - by (unfold stage_def split_def ,simp only: evaldjf_ex iupt_set simpfm) simp - -lemma stage_nb: assumes lp: "iszlfm p (a#bs)" and cp: "c >0" and nb:"numbound0 e" - shows "bound0 (stage p d (e,c))" -proof- - let ?f = "\ j. simpfm (\ p c (Add e (C j)))" - have th: "\ j\ set (iupt(1,c*d)). bound0 (?f j)" - proof - fix j - from nb have nb':"numbound0 (Add e (C j))" by simp - from simpfm_bound0[OF \_nb[OF lp nb', where k="c"]] - show "bound0 (simpfm (\ p c (Add e (C j))))" . - qed - from evaldjf_bound0[OF th] show ?thesis by (unfold stage_def split_def) simp -qed - -constdefs redlove:: "fm \ fm" - "redlove p \ - (let (q,B,d) = chooset p; - mq = simpfm (minusinf q); - md = evaldjf (\ j. simpfm (subst0 (C j) mq)) (iupt (1,d)) - in if md = T then T else - (let qd = evaldjf (stage q d) B - in decr (disj md qd)))" - -lemma redlove: assumes qf: "qfree p" - shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (redlove p))) \ qfree (redlove p)" - (is "(?lhs = ?rhs) \ _") -proof- - - let ?I = "\ (x::int) p. Ifm (real x#bs) p" - let ?q = "fst (chooset p)" - let ?B = "fst (snd(chooset p))" - let ?d = "snd (snd (chooset p))" - let ?js = "iupt (1,?d)" - let ?mq = "minusinf ?q" - let ?smq = "simpfm ?mq" - let ?md = "evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js" - fix i - let ?N = "\ (t,k). (Inum (real (i::int)#bs) t,k)" - let ?qd = "evaldjf (stage ?q ?d) ?B" - have qbf:"chooset p = (?q,?B,?d)" by simp - from chooset[OF qf qbf] have pq_ex: "(\(x::int). ?I x p) = (\ (x::int). ?I x ?q)" and - B:"?N ` set ?B = ?N ` set (\ ?q)" and dd: "\ ?q = ?d" and dp: "?d > 0" and - lq: "iszlfm ?q (real i#bs)" and - Bn: "\ (e,c)\ set ?B. numbound0 e \ c > 0" by auto - from zlin_qfree[OF lq] have qfq: "qfree ?q" . - from simpfm_qf[OF minusinf_qfree[OF qfq]] have qfmq: "qfree ?smq". - have jsnb: "\ j \ set ?js. numbound0 (C j)" by simp - hence "\ j\ set ?js. bound0 (subst0 (C j) ?smq)" - by (auto simp only: subst0_bound0[OF qfmq]) - hence th: "\ j\ set ?js. bound0 (simpfm (subst0 (C j) ?smq))" - by (auto simp add: simpfm_bound0) - from evaldjf_bound0[OF th] have mdb: "bound0 ?md" by simp - from Bn stage_nb[OF lq] have th:"\ x \ set ?B. bound0 (stage ?q ?d x)" by auto - from evaldjf_bound0[OF th] have qdb: "bound0 ?qd" . - from mdb qdb - have mdqdb: "bound0 (disj ?md ?qd)" by (simp only: disj_def, cases "?md=T \ ?qd=T", simp_all) - from trans [OF pq_ex rl_thm'[OF lq B]] dd - have "?lhs = ((\ j\ {1.. ?d}. ?I j ?mq) \ (\ (e,c)\ set ?B. \ j\ {1 .. c*?d}. Ifm (real i#bs) (\ ?q c (Add e (C j)))))" by auto - also have "\ = ((\ j\ {1.. ?d}. ?I j ?smq) \ (\ (e,c)\ set ?B. ?I i (stage ?q ?d (e,c) )))" - by (simp add: simpfm stage split_def) - also have "\ = ((\ j\ {1 .. ?d}. ?I i (subst0 (C j) ?smq)) \ ?I i ?qd)" - by (simp add: evaldjf_ex subst0_I[OF qfmq]) - finally have mdqd:"?lhs = (?I i ?md \ ?I i ?qd)" by (simp only: evaldjf_ex iupt_set simpfm) - also have "\ = (?I i (disj ?md ?qd))" by (simp add: disj) - also have "\ = (Ifm bs (decr (disj ?md ?qd)))" by (simp only: decr [OF mdqdb]) - finally have mdqd2: "?lhs = (Ifm bs (decr (disj ?md ?qd)))" . - {assume mdT: "?md = T" - hence cT:"redlove p = T" by (simp add: redlove_def Let_def chooset_def split_def) - from mdT have lhs:"?lhs" using mdqd by simp - from mdT have "?rhs" by (simp add: redlove_def chooset_def split_def) - with lhs cT have ?thesis by simp } - moreover - {assume mdT: "?md \ T" hence "redlove p = decr (disj ?md ?qd)" - by (simp add: redlove_def chooset_def split_def Let_def) - with mdqd2 decr_qf[OF mdqdb] have ?thesis by simp } - ultimately show ?thesis by blast -qed - -lemma DJredlove: - assumes qf: "qfree p" - shows "((\ (x::int). Ifm (real x#bs) p) = (Ifm bs (DJ redlove p))) \ qfree (DJ redlove p)" -proof- - from redlove have cqf: "\ p. qfree p \ qfree (redlove p)" by blast - from DJ_qf[OF cqf] qf have thqf:"qfree (DJ redlove p)" by blast - have "Ifm bs (DJ redlove p) = (\ q\ set (disjuncts p). Ifm bs (redlove q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = (\ q \ set(disjuncts p). \ (x::int). Ifm (real x#bs) q)" - using redlove disjuncts_qf[OF qf] by blast - also have "\ = (\ (x::int). Ifm (real x#bs) p)" by (induct p rule: disjuncts.induct, auto) - finally show ?thesis using thqf by blast -qed - - -lemma exsplit_qf: assumes qf: "qfree p" - shows "qfree (exsplit p)" -using qf by (induct p rule: exsplit.induct, auto) - -definition mircfr :: "fm \ fm" where - "mircfr = DJ cooper o ferrack01 o simpfm o exsplit" - -definition mirlfr :: "fm \ fm" where - "mirlfr = DJ redlove o ferrack01 o simpfm o exsplit" - -lemma mircfr: "\ bs p. qfree p \ qfree (mircfr p) \ Ifm bs (mircfr p) = Ifm bs (E p)" -proof(clarsimp simp del: Ifm.simps) - fix bs p - assume qf: "qfree p" - show "qfree (mircfr p)\(Ifm bs (mircfr p) = Ifm bs (E p))" (is "_ \ (?lhs = ?rhs)") - proof- - let ?es = "(And (And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) (simpfm (exsplit p)))" - have "?rhs = (\ (i::int). \ x. Ifm (x#real i#bs) ?es)" - using splitex[OF qf] by simp - with ferrack01[OF simpfm_qf[OF exsplit_qf[OF qf]]] have th1: "?rhs = (\ (i::int). Ifm (real i#bs) (ferrack01 (simpfm (exsplit p))))" and qf':"qfree (ferrack01 (simpfm (exsplit p)))" by simp+ - with DJcooper[OF qf'] show ?thesis by (simp add: mircfr_def) - qed -qed - -lemma mirlfr: "\ bs p. qfree p \ qfree(mirlfr p) \ Ifm bs (mirlfr p) = Ifm bs (E p)" -proof(clarsimp simp del: Ifm.simps) - fix bs p - assume qf: "qfree p" - show "qfree (mirlfr p)\(Ifm bs (mirlfr p) = Ifm bs (E p))" (is "_ \ (?lhs = ?rhs)") - proof- - let ?es = "(And (And (Ge (CN 0 1 (C 0))) (Lt (CN 0 1 (C (- 1))))) (simpfm (exsplit p)))" - have "?rhs = (\ (i::int). \ x. Ifm (x#real i#bs) ?es)" - using splitex[OF qf] by simp - with ferrack01[OF simpfm_qf[OF exsplit_qf[OF qf]]] have th1: "?rhs = (\ (i::int). Ifm (real i#bs) (ferrack01 (simpfm (exsplit p))))" and qf':"qfree (ferrack01 (simpfm (exsplit p)))" by simp+ - with DJredlove[OF qf'] show ?thesis by (simp add: mirlfr_def) - qed -qed - -definition mircfrqe:: "fm \ fm" where - "mircfrqe p = qelim (prep p) mircfr" - -definition mirlfrqe:: "fm \ fm" where - "mirlfrqe p = qelim (prep p) mirlfr" - -theorem mircfrqe: "(Ifm bs (mircfrqe p) = Ifm bs p) \ qfree (mircfrqe p)" - using qelim_ci[OF mircfr] prep by (auto simp add: mircfrqe_def) - -theorem mirlfrqe: "(Ifm bs (mirlfrqe p) = Ifm bs p) \ qfree (mirlfrqe p)" - using qelim_ci[OF mirlfr] prep by (auto simp add: mirlfrqe_def) - -definition - "test1 (u\unit) = mircfrqe (A (And (Le (Sub (Floor (Bound 0)) (Bound 0))) (Le (Add (Bound 0) (Floor (Neg (Bound 0)))))))" - -definition - "test2 (u\unit) = mircfrqe (A (Iff (Eq (Add (Floor (Bound 0)) (Floor (Neg (Bound 0))))) (Eq (Sub (Floor (Bound 0)) (Bound 0)))))" - -definition - "test3 (u\unit) = mirlfrqe (A (And (Le (Sub (Floor (Bound 0)) (Bound 0))) (Le (Add (Bound 0) (Floor (Neg (Bound 0)))))))" - -definition - "test4 (u\unit) = mirlfrqe (A (Iff (Eq (Add (Floor (Bound 0)) (Floor (Neg (Bound 0))))) (Eq (Sub (Floor (Bound 0)) (Bound 0)))))" - -definition - "test5 (u\unit) = mircfrqe (A(E(And (Ge(Sub (Bound 1) (Bound 0))) (Eq (Add (Floor (Bound 1)) (Floor (Neg(Bound 0))))))))" - -ML {* @{code test1} () *} -ML {* @{code test2} () *} -ML {* @{code test3} () *} -ML {* @{code test4} () *} -ML {* @{code test5} () *} - -(*export_code mircfrqe mirlfrqe - in SML module_name Mir file "raw_mir.ML"*) - -oracle mirfr_oracle = {* fn (proofs, ct) => -let - -fun num_of_term vs (t as Free (xn, xT)) = (case AList.lookup (op =) vs t - of NONE => error "Variable not found in the list!" - | SOME n => @{code Bound} n) - | num_of_term vs @{term "real (0::int)"} = @{code C} 0 - | num_of_term vs @{term "real (1::int)"} = @{code C} 1 - | num_of_term vs @{term "0::real"} = @{code C} 0 - | num_of_term vs @{term "1::real"} = @{code C} 1 - | num_of_term vs (Bound i) = @{code Bound} i - | num_of_term vs (@{term "uminus :: real \ real"} $ t') = @{code Neg} (num_of_term vs t') - | num_of_term vs (@{term "op + :: real \ real \ real"} $ t1 $ t2) = - @{code Add} (num_of_term vs t1, num_of_term vs t2) - | num_of_term vs (@{term "op - :: real \ real \ real"} $ t1 $ t2) = - @{code Sub} (num_of_term vs t1, num_of_term vs t2) - | num_of_term vs (@{term "op * :: real \ real \ real"} $ t1 $ t2) = - (case (num_of_term vs t1) - of @{code C} i => @{code Mul} (i, num_of_term vs t2) - | _ => error "num_of_term: unsupported Multiplication") - | num_of_term vs (@{term "real :: int \ real"} $ (@{term "number_of :: int \ int"} $ t')) = - @{code C} (HOLogic.dest_numeral t') - | num_of_term vs (@{term "real :: int \ real"} $ (@{term "floor :: real \ int"} $ t')) = - @{code Floor} (num_of_term vs t') - | num_of_term vs (@{term "real :: int \ real"} $ (@{term "ceiling :: real \ int"} $ t')) = - @{code Neg} (@{code Floor} (@{code Neg} (num_of_term vs t'))) - | num_of_term vs (@{term "number_of :: int \ real"} $ t') = - @{code C} (HOLogic.dest_numeral t') - | num_of_term vs t = error ("num_of_term: unknown term " ^ Syntax.string_of_term @{context} t); - -fun fm_of_term vs @{term True} = @{code T} - | fm_of_term vs @{term False} = @{code F} - | fm_of_term vs (@{term "op < :: real \ real \ bool"} $ t1 $ t2) = - @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term vs (@{term "op \ :: real \ real \ bool"} $ t1 $ t2) = - @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term vs (@{term "op = :: real \ real \ bool"} $ t1 $ t2) = - @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term vs (@{term "op rdvd"} $ (@{term "real :: int \ real"} $ (@{term "number_of :: int \ int"} $ t1)) $ t2) = - @{code Dvd} (HOLogic.dest_numeral t1, num_of_term vs t2) - | fm_of_term vs (@{term "op = :: bool \ bool \ bool"} $ t1 $ t2) = - @{code Iff} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "op &"} $ t1 $ t2) = - @{code And} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "op |"} $ t1 $ t2) = - @{code Or} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "op -->"} $ t1 $ t2) = - @{code Imp} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "Not"} $ t') = - @{code NOT} (fm_of_term vs t') - | fm_of_term vs (Const ("Ex", _) $ Abs (xn, xT, p)) = - @{code E} (fm_of_term (map (fn (v, n) => (v, n + 1)) vs) p) - | fm_of_term vs (Const ("All", _) $ Abs (xn, xT, p)) = - @{code A} (fm_of_term (map (fn (v, n) => (v, n + 1)) vs) p) - | fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); - -fun term_of_num vs (@{code C} i) = @{term "real :: int \ real"} $ HOLogic.mk_number HOLogic.intT i - | term_of_num vs (@{code Bound} n) = fst (the (find_first (fn (_, m) => n = m) vs)) - | term_of_num vs (@{code Neg} (@{code Floor} (@{code Neg} t'))) = - @{term "real :: int \ real"} $ (@{term "ceiling :: real \ int"} $ term_of_num vs t') - | term_of_num vs (@{code Neg} t') = @{term "uminus :: real \ real"} $ term_of_num vs t' - | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \ real \ real"} $ - term_of_num vs t1 $ term_of_num vs t2 - | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \ real \ real"} $ - term_of_num vs t1 $ term_of_num vs t2 - | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \ real \ real"} $ - term_of_num vs (@{code C} i) $ term_of_num vs t2 - | term_of_num vs (@{code Floor} t) = @{term "real :: int \ real"} $ (@{term "floor :: real \ int"} $ term_of_num vs t) - | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)) - | term_of_num vs (@{code CF} (c, t, s)) = term_of_num vs (@{code Add} (@{code Mul} (c, @{code Floor} t), s)); - -fun term_of_fm vs @{code T} = HOLogic.true_const - | term_of_fm vs @{code F} = HOLogic.false_const - | term_of_fm vs (@{code Lt} t) = - @{term "op < :: real \ real \ bool"} $ term_of_num vs t $ @{term "0::real"} - | term_of_fm vs (@{code Le} t) = - @{term "op \ :: real \ real \ bool"} $ term_of_num vs t $ @{term "0::real"} - | term_of_fm vs (@{code Gt} t) = - @{term "op < :: real \ real \ bool"} $ @{term "0::real"} $ term_of_num vs t - | term_of_fm vs (@{code Ge} t) = - @{term "op \ :: real \ real \ bool"} $ @{term "0::real"} $ term_of_num vs t - | term_of_fm vs (@{code Eq} t) = - @{term "op = :: real \ real \ bool"} $ term_of_num vs t $ @{term "0::real"} - | term_of_fm vs (@{code NEq} t) = - term_of_fm vs (@{code NOT} (@{code Eq} t)) - | term_of_fm vs (@{code Dvd} (i, t)) = - @{term "op rdvd"} $ term_of_num vs (@{code C} i) $ term_of_num vs t - | term_of_fm vs (@{code NDvd} (i, t)) = - term_of_fm vs (@{code NOT} (@{code Dvd} (i, t))) - | term_of_fm vs (@{code NOT} t') = - HOLogic.Not $ term_of_fm vs t' - | term_of_fm vs (@{code And} (t1, t2)) = - HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs (@{code Or} (t1, t2)) = - HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs (@{code Imp} (t1, t2)) = - HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs (@{code Iff} (t1, t2)) = - @{term "op = :: bool \ bool \ bool"} $ term_of_fm vs t1 $ term_of_fm vs t2; - -in - let - val thy = Thm.theory_of_cterm ct; - val t = Thm.term_of ct; - val fs = OldTerm.term_frees t; - val vs = fs ~~ (0 upto (length fs - 1)); - val qe = if proofs then @{code mirlfrqe} else @{code mircfrqe}; - val t' = (term_of_fm vs o qe o fm_of_term vs) t; - in (cterm_of thy o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end -end; -*} - -use "mirtac.ML" -setup "MirTac.setup" - -lemma "ALL (x::real). (\x\ = \x\ = (x = real \x\))" -apply mir -done - -lemma "ALL (x::real). real (2::int)*x - (real (1::int)) < real \x\ + real \x\ \ real \x\ + real \x\ \ real (2::int)*x + (real (1::int))" -apply mir -done - -lemma "ALL (x::real). 2*\x\ \ \2*x\ \ \2*x\ \ 2*\x+1\" -apply mir -done - -lemma "ALL (x::real). \y \ x. (\x\ = \y\)" -apply mir -done - -lemma "ALL x y. \x\ = \y\ \ 0 \ abs (y - x) \ abs (y - x) \ 1" -apply mir -done - -end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/ROOT.ML --- a/src/HOL/ex/ROOT.ML Tue Feb 03 16:50:40 2009 +0100 +++ b/src/HOL/ex/ROOT.ML Tue Feb 03 16:50:41 2009 +0100 @@ -15,8 +15,7 @@ "Codegenerator", "Codegenerator_Pretty", "NormalForm", - "../NumberTheory/Factorization", - "../Library/BigO" + "../NumberTheory/Factorization" ]; use_thys [ @@ -62,16 +61,12 @@ "Coherent", "Dense_Linear_Order_Ex", "PresburgerEx", - "Reflected_Presburger", "ReflectionEx", "BinEx", "Sqrt", "Sqrt_Script", - "BigO_Complex", "Arithmetic_Series_Complex", "HarmonicSeries", - "MIR", - "ReflectedFerrack", "Refute_Examples", "Quickcheck_Examples", "Formal_Power_Series_Examples" diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/ReflectedFerrack.thy --- a/src/HOL/ex/ReflectedFerrack.thy Tue Feb 03 16:50:40 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2101 +0,0 @@ -(* Title: HOL/ex/ReflectedFerrack.thy - Author: Amine Chaieb -*) - -theory ReflectedFerrack -imports Main GCD Real Efficient_Nat -uses ("linrtac.ML") -begin - -section {* Quantifier elimination for @{text "\ (0, 1, +, <)"} *} - - (*********************************************************************************) - (* SOME GENERAL STUFF< HAS TO BE MOVED IN SOME LIB *) - (*********************************************************************************) - -consts alluopairs:: "'a list \ ('a \ 'a) list" -primrec - "alluopairs [] = []" - "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)" - -lemma alluopairs_set1: "set (alluopairs xs) \ {(x,y). x\ set xs \ y\ set xs}" -by (induct xs, auto) - -lemma alluopairs_set: - "\x\ set xs ; y \ set xs\ \ (x,y) \ set (alluopairs xs) \ (y,x) \ set (alluopairs xs) " -by (induct xs, auto) - -lemma alluopairs_ex: - assumes Pc: "\ x y. P x y = P y x" - shows "(\ x \ set xs. \ y \ set xs. P x y) = (\ (x,y) \ set (alluopairs xs). P x y)" -proof - assume "\x\set xs. \y\set xs. P x y" - then obtain x y where x: "x \ set xs" and y:"y \ set xs" and P: "P x y" by blast - from alluopairs_set[OF x y] P Pc show"\(x, y)\set (alluopairs xs). P x y" - by auto -next - assume "\(x, y)\set (alluopairs xs). P x y" - then obtain "x" and "y" where xy:"(x,y) \ set (alluopairs xs)" and P: "P x y" by blast+ - from xy have "x \ set xs \ y\ set xs" using alluopairs_set1 by blast - with P show "\x\set xs. \y\set xs. P x y" by blast -qed - -lemma nth_pos2: "0 < n \ (x#xs) ! n = xs ! (n - 1)" -using Nat.gr0_conv_Suc -by clarsimp - -lemma filter_length: "length (List.filter P xs) < Suc (length xs)" - apply (induct xs, auto) done - -consts remdps:: "'a list \ 'a list" - -recdef remdps "measure size" - "remdps [] = []" - "remdps (x#xs) = (x#(remdps (List.filter (\ y. y \ x) xs)))" -(hints simp add: filter_length[rule_format]) - -lemma remdps_set[simp]: "set (remdps xs) = set xs" - by (induct xs rule: remdps.induct, auto) - - - - (*********************************************************************************) - (**** SHADOW SYNTAX AND SEMANTICS ****) - (*********************************************************************************) - -datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num - | Mul int num - - (* A size for num to make inductive proofs simpler*) -consts num_size :: "num \ nat" -primrec - "num_size (C c) = 1" - "num_size (Bound n) = 1" - "num_size (Neg a) = 1 + num_size a" - "num_size (Add a b) = 1 + num_size a + num_size b" - "num_size (Sub a b) = 3 + num_size a + num_size b" - "num_size (Mul c a) = 1 + num_size a" - "num_size (CN n c a) = 3 + num_size a " - - (* Semantics of numeral terms (num) *) -consts Inum :: "real list \ num \ real" -primrec - "Inum bs (C c) = (real c)" - "Inum bs (Bound n) = bs!n" - "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)" - "Inum bs (Neg a) = -(Inum bs a)" - "Inum bs (Add a b) = Inum bs a + Inum bs b" - "Inum bs (Sub a b) = Inum bs a - Inum bs b" - "Inum bs (Mul c a) = (real c) * Inum bs a" - (* FORMULAE *) -datatype fm = - T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| - NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm - - - (* A size for fm *) -consts fmsize :: "fm \ nat" -recdef fmsize "measure size" - "fmsize (NOT p) = 1 + fmsize p" - "fmsize (And p q) = 1 + fmsize p + fmsize q" - "fmsize (Or p q) = 1 + fmsize p + fmsize q" - "fmsize (Imp p q) = 3 + fmsize p + fmsize q" - "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" - "fmsize (E p) = 1 + fmsize p" - "fmsize (A p) = 4+ fmsize p" - "fmsize p = 1" - (* several lemmas about fmsize *) -lemma fmsize_pos: "fmsize p > 0" -by (induct p rule: fmsize.induct) simp_all - - (* Semantics of formulae (fm) *) -consts Ifm ::"real list \ fm \ bool" -primrec - "Ifm bs T = True" - "Ifm bs F = False" - "Ifm bs (Lt a) = (Inum bs a < 0)" - "Ifm bs (Gt a) = (Inum bs a > 0)" - "Ifm bs (Le a) = (Inum bs a \ 0)" - "Ifm bs (Ge a) = (Inum bs a \ 0)" - "Ifm bs (Eq a) = (Inum bs a = 0)" - "Ifm bs (NEq a) = (Inum bs a \ 0)" - "Ifm bs (NOT p) = (\ (Ifm bs p))" - "Ifm bs (And p q) = (Ifm bs p \ Ifm bs q)" - "Ifm bs (Or p q) = (Ifm bs p \ Ifm bs q)" - "Ifm bs (Imp p q) = ((Ifm bs p) \ (Ifm bs q))" - "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)" - "Ifm bs (E p) = (\ x. Ifm (x#bs) p)" - "Ifm bs (A p) = (\ x. Ifm (x#bs) p)" - -lemma IfmLeSub: "\ Inum bs s = s' ; Inum bs t = t' \ \ Ifm bs (Le (Sub s t)) = (s' \ t')" -apply simp -done - -lemma IfmLtSub: "\ Inum bs s = s' ; Inum bs t = t' \ \ Ifm bs (Lt (Sub s t)) = (s' < t')" -apply simp -done -lemma IfmEqSub: "\ Inum bs s = s' ; Inum bs t = t' \ \ Ifm bs (Eq (Sub s t)) = (s' = t')" -apply simp -done -lemma IfmNOT: " (Ifm bs p = P) \ (Ifm bs (NOT p) = (\P))" -apply simp -done -lemma IfmAnd: " \ Ifm bs p = P ; Ifm bs q = Q\ \ (Ifm bs (And p q) = (P \ Q))" -apply simp -done -lemma IfmOr: " \ Ifm bs p = P ; Ifm bs q = Q\ \ (Ifm bs (Or p q) = (P \ Q))" -apply simp -done -lemma IfmImp: " \ Ifm bs p = P ; Ifm bs q = Q\ \ (Ifm bs (Imp p q) = (P \ Q))" -apply simp -done -lemma IfmIff: " \ Ifm bs p = P ; Ifm bs q = Q\ \ (Ifm bs (Iff p q) = (P = Q))" -apply simp -done - -lemma IfmE: " (!! x. Ifm (x#bs) p = P x) \ (Ifm bs (E p) = (\x. P x))" -apply simp -done -lemma IfmA: " (!! x. Ifm (x#bs) p = P x) \ (Ifm bs (A p) = (\x. P x))" -apply simp -done - -consts not:: "fm \ fm" -recdef not "measure size" - "not (NOT p) = p" - "not T = F" - "not F = T" - "not p = NOT p" -lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)" -by (cases p) auto - -constdefs conj :: "fm \ fm \ fm" - "conj p q \ (if (p = F \ q=F) then F else if p=T then q else if q=T then p else - if p = q then p else And p q)" -lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)" -by (cases "p=F \ q=F",simp_all add: conj_def) (cases p,simp_all) - -constdefs disj :: "fm \ fm \ fm" - "disj p q \ (if (p = T \ q=T) then T else if p=F then q else if q=F then p - else if p=q then p else Or p q)" - -lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)" -by (cases "p=T \ q=T",simp_all add: disj_def) (cases p,simp_all) - -constdefs imp :: "fm \ fm \ fm" - "imp p q \ (if (p = F \ q=T \ p=q) then T else if p=T then q else if q=F then not p - else Imp p q)" -lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)" -by (cases "p=F \ q=T",simp_all add: imp_def) - -constdefs iff :: "fm \ fm \ fm" - "iff p q \ (if (p = q) then T else if (p = NOT q \ NOT p = q) then F else - if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else - Iff p q)" -lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)" - by (unfold iff_def,cases "p=q", simp,cases "p=NOT q", simp) (cases "NOT p= q", auto) - -lemma conj_simps: - "conj F Q = F" - "conj P F = F" - "conj T Q = Q" - "conj P T = P" - "conj P P = P" - "P \ T \ P \ F \ Q \ T \ Q \ F \ P \ Q \ conj P Q = And P Q" - by (simp_all add: conj_def) - -lemma disj_simps: - "disj T Q = T" - "disj P T = T" - "disj F Q = Q" - "disj P F = P" - "disj P P = P" - "P \ T \ P \ F \ Q \ T \ Q \ F \ P \ Q \ disj P Q = Or P Q" - by (simp_all add: disj_def) -lemma imp_simps: - "imp F Q = T" - "imp P T = T" - "imp T Q = Q" - "imp P F = not P" - "imp P P = T" - "P \ T \ P \ F \ P \ Q \ Q \ T \ Q \ F \ imp P Q = Imp P Q" - by (simp_all add: imp_def) -lemma trivNOT: "p \ NOT p" "NOT p \ p" -apply (induct p, auto) -done - -lemma iff_simps: - "iff p p = T" - "iff p (NOT p) = F" - "iff (NOT p) p = F" - "iff p F = not p" - "iff F p = not p" - "p \ NOT T \ iff T p = p" - "p\ NOT T \ iff p T = p" - "p\q \ p\ NOT q \ q\ NOT p \ p\ F \ q\ F \ p \ T \ q \ T \ iff p q = Iff p q" - using trivNOT - by (simp_all add: iff_def, cases p, auto) - (* Quantifier freeness *) -consts qfree:: "fm \ bool" -recdef qfree "measure size" - "qfree (E p) = False" - "qfree (A p) = False" - "qfree (NOT p) = qfree p" - "qfree (And p q) = (qfree p \ qfree q)" - "qfree (Or p q) = (qfree p \ qfree q)" - "qfree (Imp p q) = (qfree p \ qfree q)" - "qfree (Iff p q) = (qfree p \ qfree q)" - "qfree p = True" - - (* Boundedness and substitution *) -consts - numbound0:: "num \ bool" (* a num is INDEPENDENT of Bound 0 *) - bound0:: "fm \ bool" (* A Formula is independent of Bound 0 *) -primrec - "numbound0 (C c) = True" - "numbound0 (Bound n) = (n>0)" - "numbound0 (CN n c a) = (n\0 \ numbound0 a)" - "numbound0 (Neg a) = numbound0 a" - "numbound0 (Add a b) = (numbound0 a \ numbound0 b)" - "numbound0 (Sub a b) = (numbound0 a \ numbound0 b)" - "numbound0 (Mul i a) = numbound0 a" -lemma numbound0_I: - assumes nb: "numbound0 a" - shows "Inum (b#bs) a = Inum (b'#bs) a" -using nb -by (induct a rule: numbound0.induct,auto simp add: nth_pos2) - -primrec - "bound0 T = True" - "bound0 F = True" - "bound0 (Lt a) = numbound0 a" - "bound0 (Le a) = numbound0 a" - "bound0 (Gt a) = numbound0 a" - "bound0 (Ge a) = numbound0 a" - "bound0 (Eq a) = numbound0 a" - "bound0 (NEq a) = numbound0 a" - "bound0 (NOT p) = bound0 p" - "bound0 (And p q) = (bound0 p \ bound0 q)" - "bound0 (Or p q) = (bound0 p \ bound0 q)" - "bound0 (Imp p q) = ((bound0 p) \ (bound0 q))" - "bound0 (Iff p q) = (bound0 p \ bound0 q)" - "bound0 (E p) = False" - "bound0 (A p) = False" - -lemma bound0_I: - assumes bp: "bound0 p" - shows "Ifm (b#bs) p = Ifm (b'#bs) p" -using bp numbound0_I[where b="b" and bs="bs" and b'="b'"] -by (induct p rule: bound0.induct) (auto simp add: nth_pos2) - -lemma not_qf[simp]: "qfree p \ qfree (not p)" -by (cases p, auto) -lemma not_bn[simp]: "bound0 p \ bound0 (not p)" -by (cases p, auto) - - -lemma conj_qf[simp]: "\qfree p ; qfree q\ \ qfree (conj p q)" -using conj_def by auto -lemma conj_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (conj p q)" -using conj_def by auto - -lemma disj_qf[simp]: "\qfree p ; qfree q\ \ qfree (disj p q)" -using disj_def by auto -lemma disj_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (disj p q)" -using disj_def by auto - -lemma imp_qf[simp]: "\qfree p ; qfree q\ \ qfree (imp p q)" -using imp_def by (cases "p=F \ q=T",simp_all add: imp_def) -lemma imp_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (imp p q)" -using imp_def by (cases "p=F \ q=T \ p=q",simp_all add: imp_def) - -lemma iff_qf[simp]: "\qfree p ; qfree q\ \ qfree (iff p q)" - by (unfold iff_def,cases "p=q", auto) -lemma iff_nb[simp]: "\bound0 p ; bound0 q\ \ bound0 (iff p q)" -using iff_def by (unfold iff_def,cases "p=q", auto) - -consts - decrnum:: "num \ num" - decr :: "fm \ fm" - -recdef decrnum "measure size" - "decrnum (Bound n) = Bound (n - 1)" - "decrnum (Neg a) = Neg (decrnum a)" - "decrnum (Add a b) = Add (decrnum a) (decrnum b)" - "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" - "decrnum (Mul c a) = Mul c (decrnum a)" - "decrnum (CN n c a) = CN (n - 1) c (decrnum a)" - "decrnum a = a" - -recdef decr "measure size" - "decr (Lt a) = Lt (decrnum a)" - "decr (Le a) = Le (decrnum a)" - "decr (Gt a) = Gt (decrnum a)" - "decr (Ge a) = Ge (decrnum a)" - "decr (Eq a) = Eq (decrnum a)" - "decr (NEq a) = NEq (decrnum a)" - "decr (NOT p) = NOT (decr p)" - "decr (And p q) = conj (decr p) (decr q)" - "decr (Or p q) = disj (decr p) (decr q)" - "decr (Imp p q) = imp (decr p) (decr q)" - "decr (Iff p q) = iff (decr p) (decr q)" - "decr p = p" - -lemma decrnum: assumes nb: "numbound0 t" - shows "Inum (x#bs) t = Inum bs (decrnum t)" - using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2) - -lemma decr: assumes nb: "bound0 p" - shows "Ifm (x#bs) p = Ifm bs (decr p)" - using nb - by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum) - -lemma decr_qf: "bound0 p \ qfree (decr p)" -by (induct p, simp_all) - -consts - isatom :: "fm \ bool" (* test for atomicity *) -recdef isatom "measure size" - "isatom T = True" - "isatom F = True" - "isatom (Lt a) = True" - "isatom (Le a) = True" - "isatom (Gt a) = True" - "isatom (Ge a) = True" - "isatom (Eq a) = True" - "isatom (NEq a) = True" - "isatom p = False" - -lemma bound0_qf: "bound0 p \ qfree p" -by (induct p, simp_all) - -constdefs djf:: "('a \ fm) \ 'a \ fm \ fm" - "djf f p q \ (if q=T then T else if q=F then f p else - (let fp = f p in case fp of T \ T | F \ q | _ \ Or (f p) q))" -constdefs evaldjf:: "('a \ fm) \ 'a list \ fm" - "evaldjf f ps \ foldr (djf f) ps F" - -lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)" -by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) -(cases "f p", simp_all add: Let_def djf_def) - - -lemma djf_simps: - "djf f p T = T" - "djf f p F = f p" - "q\T \ q\F \ djf f p q = (let fp = f p in case fp of T \ T | F \ q | _ \ Or (f p) q)" - by (simp_all add: djf_def) - -lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\ p \ set ps. Ifm bs (f p))" - by(induct ps, simp_all add: evaldjf_def djf_Or) - -lemma evaldjf_bound0: - assumes nb: "\ x\ set xs. bound0 (f x)" - shows "bound0 (evaldjf f xs)" - using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) - -lemma evaldjf_qf: - assumes nb: "\ x\ set xs. qfree (f x)" - shows "qfree (evaldjf f xs)" - using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) - -consts disjuncts :: "fm \ fm list" -recdef disjuncts "measure size" - "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)" - "disjuncts F = []" - "disjuncts p = [p]" - -lemma disjuncts: "(\ q\ set (disjuncts p). Ifm bs q) = Ifm bs p" -by(induct p rule: disjuncts.induct, auto) - -lemma disjuncts_nb: "bound0 p \ \ q\ set (disjuncts p). bound0 q" -proof- - assume nb: "bound0 p" - hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto) - thus ?thesis by (simp only: list_all_iff) -qed - -lemma disjuncts_qf: "qfree p \ \ q\ set (disjuncts p). qfree q" -proof- - assume qf: "qfree p" - hence "list_all qfree (disjuncts p)" - by (induct p rule: disjuncts.induct, auto) - thus ?thesis by (simp only: list_all_iff) -qed - -constdefs DJ :: "(fm \ fm) \ fm \ fm" - "DJ f p \ evaldjf f (disjuncts p)" - -lemma DJ: assumes fdj: "\ p q. Ifm bs (f (Or p q)) = Ifm bs (Or (f p) (f q))" - and fF: "f F = F" - shows "Ifm bs (DJ f p) = Ifm bs (f p)" -proof- - have "Ifm bs (DJ f p) = (\ q \ set (disjuncts p). Ifm bs (f q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto) - finally show ?thesis . -qed - -lemma DJ_qf: assumes - fqf: "\ p. qfree p \ qfree (f p)" - shows "\p. qfree p \ qfree (DJ f p) " -proof(clarify) - fix p assume qf: "qfree p" - have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def) - from disjuncts_qf[OF qf] have "\ q\ set (disjuncts p). qfree q" . - with fqf have th':"\ q\ set (disjuncts p). qfree (f q)" by blast - - from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp -qed - -lemma DJ_qe: assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" - shows "\ bs p. qfree p \ qfree (DJ qe p) \ (Ifm bs ((DJ qe p)) = Ifm bs (E p))" -proof(clarify) - fix p::fm and bs - assume qf: "qfree p" - from qe have qth: "\ p. qfree p \ qfree (qe p)" by blast - from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto - have "Ifm bs (DJ qe p) = (\ q\ set (disjuncts p). Ifm bs (qe q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = (\ q \ set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto - also have "\ = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto) - finally show "qfree (DJ qe p) \ Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast -qed - (* Simplification *) -consts - numgcd :: "num \ int" - numgcdh:: "num \ int \ int" - reducecoeffh:: "num \ int \ num" - reducecoeff :: "num \ num" - dvdnumcoeff:: "num \ int \ bool" -consts maxcoeff:: "num \ int" -recdef maxcoeff "measure size" - "maxcoeff (C i) = abs i" - "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)" - "maxcoeff t = 1" - -lemma maxcoeff_pos: "maxcoeff t \ 0" - by (induct t rule: maxcoeff.induct, auto) - -recdef numgcdh "measure size" - "numgcdh (C i) = (\g. zgcd i g)" - "numgcdh (CN n c t) = (\g. zgcd c (numgcdh t g))" - "numgcdh t = (\g. 1)" -defs numgcd_def [code]: "numgcd t \ numgcdh t (maxcoeff t)" - -recdef reducecoeffh "measure size" - "reducecoeffh (C i) = (\ g. C (i div g))" - "reducecoeffh (CN n c t) = (\ g. CN n (c div g) (reducecoeffh t g))" - "reducecoeffh t = (\g. t)" - -defs reducecoeff_def: "reducecoeff t \ - (let g = numgcd t in - if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)" - -recdef dvdnumcoeff "measure size" - "dvdnumcoeff (C i) = (\ g. g dvd i)" - "dvdnumcoeff (CN n c t) = (\ g. g dvd c \ (dvdnumcoeff t g))" - "dvdnumcoeff t = (\g. False)" - -lemma dvdnumcoeff_trans: - assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'" - shows "dvdnumcoeff t g" - using dgt' gdg - by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg zdvd_trans[OF gdg]) - -declare zdvd_trans [trans add] - -lemma natabs0: "(nat (abs x) = 0) = (x = 0)" -by arith - -lemma numgcd0: - assumes g0: "numgcd t = 0" - shows "Inum bs t = 0" - using g0[simplified numgcd_def] - by (induct t rule: numgcdh.induct, auto simp add: zgcd_def gcd_zero natabs0 max_def maxcoeff_pos) - -lemma numgcdh_pos: assumes gp: "g \ 0" shows "numgcdh t g \ 0" - using gp - by (induct t rule: numgcdh.induct, auto simp add: zgcd_def) - -lemma numgcd_pos: "numgcd t \0" - by (simp add: numgcd_def numgcdh_pos maxcoeff_pos) - -lemma reducecoeffh: - assumes gt: "dvdnumcoeff t g" and gp: "g > 0" - shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t" - using gt -proof(induct t rule: reducecoeffh.induct) - case (1 i) hence gd: "g dvd i" by simp - from gp have gnz: "g \ 0" by simp - from prems show ?case by (simp add: real_of_int_div[OF gnz gd]) -next - case (2 n c t) hence gd: "g dvd c" by simp - from gp have gnz: "g \ 0" by simp - from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps) -qed (auto simp add: numgcd_def gp) -consts ismaxcoeff:: "num \ int \ bool" -recdef ismaxcoeff "measure size" - "ismaxcoeff (C i) = (\ x. abs i \ x)" - "ismaxcoeff (CN n c t) = (\x. abs c \ x \ (ismaxcoeff t x))" - "ismaxcoeff t = (\x. True)" - -lemma ismaxcoeff_mono: "ismaxcoeff t c \ c \ c' \ ismaxcoeff t c'" -by (induct t rule: ismaxcoeff.induct, auto) - -lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" -proof (induct t rule: maxcoeff.induct) - case (2 n c t) - hence H:"ismaxcoeff t (maxcoeff t)" . - have thh: "maxcoeff t \ max (abs c) (maxcoeff t)" by (simp add: le_maxI2) - from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1) -qed simp_all - -lemma zgcd_gt1: "zgcd i j > 1 \ ((abs i > 1 \ abs j > 1) \ (abs i = 0 \ abs j > 1) \ (abs i > 1 \ abs j = 0))" - apply (cases "abs i = 0", simp_all add: zgcd_def) - apply (cases "abs j = 0", simp_all) - apply (cases "abs i = 1", simp_all) - apply (cases "abs j = 1", simp_all) - apply auto - done -lemma numgcdh0:"numgcdh t m = 0 \ m =0" - by (induct t rule: numgcdh.induct, auto simp add:zgcd0) - -lemma dvdnumcoeff_aux: - assumes "ismaxcoeff t m" and mp:"m \ 0" and "numgcdh t m > 1" - shows "dvdnumcoeff t (numgcdh t m)" -using prems -proof(induct t rule: numgcdh.induct) - case (2 n c t) - let ?g = "numgcdh t m" - from prems have th:"zgcd c ?g > 1" by simp - from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] - have "(abs c > 1 \ ?g > 1) \ (abs c = 0 \ ?g > 1) \ (abs c > 1 \ ?g = 0)" by simp - moreover {assume "abs c > 1" and gp: "?g > 1" with prems - have th: "dvdnumcoeff t ?g" by simp - have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) - from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)} - moreover {assume "abs c = 0 \ ?g > 1" - with prems have th: "dvdnumcoeff t ?g" by simp - have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2) - from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1) - hence ?case by simp } - moreover {assume "abs c > 1" and g0:"?g = 0" - from numgcdh0[OF g0] have "m=0". with prems have ?case by simp } - ultimately show ?case by blast -qed(auto simp add: zgcd_zdvd1) - -lemma dvdnumcoeff_aux2: - assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \ numgcd t > 0" - using prems -proof (simp add: numgcd_def) - let ?mc = "maxcoeff t" - let ?g = "numgcdh t ?mc" - have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff) - have th2: "?mc \ 0" by (rule maxcoeff_pos) - assume H: "numgcdh t ?mc > 1" - from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" . -qed - -lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t" -proof- - let ?g = "numgcd t" - have "?g \ 0" by (simp add: numgcd_pos) - hence "?g = 0 \ ?g = 1 \ ?g > 1" by auto - moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} - moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} - moreover { assume g1:"?g > 1" - from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+ - from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis - by (simp add: reducecoeff_def Let_def)} - ultimately show ?thesis by blast -qed - -lemma reducecoeffh_numbound0: "numbound0 t \ numbound0 (reducecoeffh t g)" -by (induct t rule: reducecoeffh.induct, auto) - -lemma reducecoeff_numbound0: "numbound0 t \ numbound0 (reducecoeff t)" -using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def) - -consts - simpnum:: "num \ num" - numadd:: "num \ num \ num" - nummul:: "num \ int \ num" -recdef numadd "measure (\ (t,s). size t + size s)" - "numadd (CN n1 c1 r1,CN n2 c2 r2) = - (if n1=n2 then - (let c = c1 + c2 - in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2)))) - else if n1 \ n2 then (CN n1 c1 (numadd (r1,CN n2 c2 r2))) - else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))" - "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))" - "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" - "numadd (C b1, C b2) = C (b1+b2)" - "numadd (a,b) = Add a b" - -lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" -apply (induct t s rule: numadd.induct, simp_all add: Let_def) -apply (case_tac "c1+c2 = 0",case_tac "n1 \ n2", simp_all) -apply (case_tac "n1 = n2", simp_all add: algebra_simps) -by (simp only: left_distrib[symmetric],simp) - -lemma numadd_nb[simp]: "\ numbound0 t ; numbound0 s\ \ numbound0 (numadd (t,s))" -by (induct t s rule: numadd.induct, auto simp add: Let_def) - -recdef nummul "measure size" - "nummul (C j) = (\ i. C (i*j))" - "nummul (CN n c a) = (\ i. CN n (i*c) (nummul a i))" - "nummul t = (\ i. Mul i t)" - -lemma nummul[simp]: "\ i. Inum bs (nummul t i) = Inum bs (Mul i t)" -by (induct t rule: nummul.induct, auto simp add: algebra_simps) - -lemma nummul_nb[simp]: "\ i. numbound0 t \ numbound0 (nummul t i)" -by (induct t rule: nummul.induct, auto ) - -constdefs numneg :: "num \ num" - "numneg t \ nummul t (- 1)" - -constdefs numsub :: "num \ num \ num" - "numsub s t \ (if s = t then C 0 else numadd (s,numneg t))" - -lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)" -using numneg_def by simp - -lemma numneg_nb[simp]: "numbound0 t \ numbound0 (numneg t)" -using numneg_def by simp - -lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)" -using numsub_def by simp - -lemma numsub_nb[simp]: "\ numbound0 t ; numbound0 s\ \ numbound0 (numsub t s)" -using numsub_def by simp - -recdef simpnum "measure size" - "simpnum (C j) = C j" - "simpnum (Bound n) = CN n 1 (C 0)" - "simpnum (Neg t) = numneg (simpnum t)" - "simpnum (Add t s) = numadd (simpnum t,simpnum s)" - "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" - "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)" - "simpnum (CN n c t) = (if c = 0 then simpnum t else numadd (CN n c (C 0),simpnum t))" - -lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t" -by (induct t rule: simpnum.induct, auto simp add: numneg numadd numsub nummul) - -lemma simpnum_numbound0[simp]: - "numbound0 t \ numbound0 (simpnum t)" -by (induct t rule: simpnum.induct, auto) - -consts nozerocoeff:: "num \ bool" -recdef nozerocoeff "measure size" - "nozerocoeff (C c) = True" - "nozerocoeff (CN n c t) = (c\0 \ nozerocoeff t)" - "nozerocoeff t = True" - -lemma numadd_nz : "nozerocoeff a \ nozerocoeff b \ nozerocoeff (numadd (a,b))" -by (induct a b rule: numadd.induct,auto simp add: Let_def) - -lemma nummul_nz : "\ i. i\0 \ nozerocoeff a \ nozerocoeff (nummul a i)" -by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz) - -lemma numneg_nz : "nozerocoeff a \ nozerocoeff (numneg a)" -by (simp add: numneg_def nummul_nz) - -lemma numsub_nz: "nozerocoeff a \ nozerocoeff b \ nozerocoeff (numsub a b)" -by (simp add: numsub_def numneg_nz numadd_nz) - -lemma simpnum_nz: "nozerocoeff (simpnum t)" -by(induct t rule: simpnum.induct, auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz) - -lemma maxcoeff_nz: "nozerocoeff t \ maxcoeff t = 0 \ t = C 0" -proof (induct t rule: maxcoeff.induct) - case (2 n c t) - hence cnz: "c \0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+ - have "max (abs c) (maxcoeff t) \ abs c" by (simp add: le_maxI1) - with cnz have "max (abs c) (maxcoeff t) > 0" by arith - with prems show ?case by simp -qed auto - -lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0" -proof- - from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def) - from numgcdh0[OF th] have th:"maxcoeff t = 0" . - from maxcoeff_nz[OF nz th] show ?thesis . -qed - -constdefs simp_num_pair:: "(num \ int) \ num \ int" - "simp_num_pair \ (\ (t,n). (if n = 0 then (C 0, 0) else - (let t' = simpnum t ; g = numgcd t' in - if g > 1 then (let g' = zgcd n g in - if g' = 1 then (t',n) - else (reducecoeffh t' g', n div g')) - else (t',n))))" - -lemma simp_num_pair_ci: - shows "((\ (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\ (t,n). Inum bs t / real n) (t,n))" - (is "?lhs = ?rhs") -proof- - let ?t' = "simpnum t" - let ?g = "numgcd ?t'" - let ?g' = "zgcd n ?g" - {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)} - moreover - { assume nnz: "n \ 0" - {assume "\ ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)} - moreover - {assume g1:"?g>1" hence g0: "?g > 0" by simp - from zgcd0 g1 nnz have gp0: "?g' \ 0" by simp - hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith - hence "?g'= 1 \ ?g' > 1" by arith - moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)} - moreover {assume g'1:"?g'>1" - from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" .. - let ?tt = "reducecoeffh ?t' ?g'" - let ?t = "Inum bs ?tt" - have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) - have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) - have gpdgp: "?g' dvd ?g'" by simp - from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] - have th2:"real ?g' * ?t = Inum bs ?t'" by simp - from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def) - also have "\ = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp - also have "\ = (Inum bs ?t' / real n)" - using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp - finally have "?lhs = Inum bs t / real n" by (simp add: simpnum_ci) - then have ?thesis using prems by (simp add: simp_num_pair_def)} - ultimately have ?thesis by blast} - ultimately have ?thesis by blast} - ultimately show ?thesis by blast -qed - -lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')" - shows "numbound0 t' \ n' >0" -proof- - let ?t' = "simpnum t" - let ?g = "numgcd ?t'" - let ?g' = "zgcd n ?g" - {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)} - moreover - { assume nnz: "n \ 0" - {assume "\ ?g > 1" hence ?thesis using prems by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0)} - moreover - {assume g1:"?g>1" hence g0: "?g > 0" by simp - from zgcd0 g1 nnz have gp0: "?g' \ 0" by simp - hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith - hence "?g'= 1 \ ?g' > 1" by arith - moreover {assume "?g'=1" hence ?thesis using prems - by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0)} - moreover {assume g'1:"?g'>1" - have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2) - have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) - have gpdgp: "?g' dvd ?g'" by simp - from zdvd_imp_le[OF gpdd np] have g'n: "?g' \ n" . - from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]] - have "n div ?g' >0" by simp - hence ?thesis using prems - by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0 simpnum_numbound0)} - ultimately have ?thesis by blast} - ultimately have ?thesis by blast} - ultimately show ?thesis by blast -qed - -consts simpfm :: "fm \ fm" -recdef simpfm "measure fmsize" - "simpfm (And p q) = conj (simpfm p) (simpfm q)" - "simpfm (Or p q) = disj (simpfm p) (simpfm q)" - "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" - "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" - "simpfm (NOT p) = not (simpfm p)" - "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \ if (v < 0) then T else F - | _ \ Lt a')" - "simpfm (Le a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Le a')" - "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \ if (v > 0) then T else F | _ \ Gt a')" - "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Ge a')" - "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \ if (v = 0) then T else F | _ \ Eq a')" - "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ NEq a')" - "simpfm p = p" -lemma simpfm: "Ifm bs (simpfm p) = Ifm bs p" -proof(induct p rule: simpfm.induct) - case (6 a) let ?sa = "simpnum a" from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (7 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (8 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (9 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (10 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (11 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not) - - -lemma simpfm_bound0: "bound0 p \ bound0 (simpfm p)" -proof(induct p rule: simpfm.induct) - case (6 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (7 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (8 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (9 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (10 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (11 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -qed(auto simp add: disj_def imp_def iff_def conj_def not_bn) - -lemma simpfm_qf: "qfree p \ qfree (simpfm p)" -by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def) - (case_tac "simpnum a",auto)+ - -consts prep :: "fm \ fm" -recdef prep "measure fmsize" - "prep (E T) = T" - "prep (E F) = F" - "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))" - "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))" - "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" - "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))" - "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" - "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" - "prep (E p) = E (prep p)" - "prep (A (And p q)) = conj (prep (A p)) (prep (A q))" - "prep (A p) = prep (NOT (E (NOT p)))" - "prep (NOT (NOT p)) = prep p" - "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))" - "prep (NOT (A p)) = prep (E (NOT p))" - "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))" - "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))" - "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))" - "prep (NOT p) = not (prep p)" - "prep (Or p q) = disj (prep p) (prep q)" - "prep (And p q) = conj (prep p) (prep q)" - "prep (Imp p q) = prep (Or (NOT p) q)" - "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))" - "prep p = p" -(hints simp add: fmsize_pos) -lemma prep: "\ bs. Ifm bs (prep p) = Ifm bs p" -by (induct p rule: prep.induct, auto) - - (* Generic quantifier elimination *) -consts qelim :: "fm \ (fm \ fm) \ fm" -recdef qelim "measure fmsize" - "qelim (E p) = (\ qe. DJ qe (qelim p qe))" - "qelim (A p) = (\ qe. not (qe ((qelim (NOT p) qe))))" - "qelim (NOT p) = (\ qe. not (qelim p qe))" - "qelim (And p q) = (\ qe. conj (qelim p qe) (qelim q qe))" - "qelim (Or p q) = (\ qe. disj (qelim p qe) (qelim q qe))" - "qelim (Imp p q) = (\ qe. imp (qelim p qe) (qelim q qe))" - "qelim (Iff p q) = (\ qe. iff (qelim p qe) (qelim q qe))" - "qelim p = (\ y. simpfm p)" - -lemma qelim_ci: - assumes qe_inv: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bs (qe p) = Ifm bs (E p))" - shows "\ bs. qfree (qelim p qe) \ (Ifm bs (qelim p qe) = Ifm bs p)" -using qe_inv DJ_qe[OF qe_inv] -by(induct p rule: qelim.induct) -(auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf - simpfm simpfm_qf simp del: simpfm.simps) - -consts - plusinf:: "fm \ fm" (* Virtual substitution of +\*) - minusinf:: "fm \ fm" (* Virtual substitution of -\*) -recdef minusinf "measure size" - "minusinf (And p q) = conj (minusinf p) (minusinf q)" - "minusinf (Or p q) = disj (minusinf p) (minusinf q)" - "minusinf (Eq (CN 0 c e)) = F" - "minusinf (NEq (CN 0 c e)) = T" - "minusinf (Lt (CN 0 c e)) = T" - "minusinf (Le (CN 0 c e)) = T" - "minusinf (Gt (CN 0 c e)) = F" - "minusinf (Ge (CN 0 c e)) = F" - "minusinf p = p" - -recdef plusinf "measure size" - "plusinf (And p q) = conj (plusinf p) (plusinf q)" - "plusinf (Or p q) = disj (plusinf p) (plusinf q)" - "plusinf (Eq (CN 0 c e)) = F" - "plusinf (NEq (CN 0 c e)) = T" - "plusinf (Lt (CN 0 c e)) = F" - "plusinf (Le (CN 0 c e)) = F" - "plusinf (Gt (CN 0 c e)) = T" - "plusinf (Ge (CN 0 c e)) = T" - "plusinf p = p" - -consts - isrlfm :: "fm \ bool" (* Linearity test for fm *) -recdef isrlfm "measure size" - "isrlfm (And p q) = (isrlfm p \ isrlfm q)" - "isrlfm (Or p q) = (isrlfm p \ isrlfm q)" - "isrlfm (Eq (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (NEq (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Lt (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Le (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Gt (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm (Ge (CN 0 c e)) = (c>0 \ numbound0 e)" - "isrlfm p = (isatom p \ (bound0 p))" - - (* splits the bounded from the unbounded part*) -consts rsplit0 :: "num \ int \ num" -recdef rsplit0 "measure num_size" - "rsplit0 (Bound 0) = (1,C 0)" - "rsplit0 (Add a b) = (let (ca,ta) = rsplit0 a ; (cb,tb) = rsplit0 b - in (ca+cb, Add ta tb))" - "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))" - "rsplit0 (Neg a) = (let (c,t) = rsplit0 a in (-c,Neg t))" - "rsplit0 (Mul c a) = (let (ca,ta) = rsplit0 a in (c*ca,Mul c ta))" - "rsplit0 (CN 0 c a) = (let (ca,ta) = rsplit0 a in (c+ca,ta))" - "rsplit0 (CN n c a) = (let (ca,ta) = rsplit0 a in (ca,CN n c ta))" - "rsplit0 t = (0,t)" -lemma rsplit0: - shows "Inum bs ((split (CN 0)) (rsplit0 t)) = Inum bs t \ numbound0 (snd (rsplit0 t))" -proof (induct t rule: rsplit0.induct) - case (2 a b) - let ?sa = "rsplit0 a" let ?sb = "rsplit0 b" - let ?ca = "fst ?sa" let ?cb = "fst ?sb" - let ?ta = "snd ?sa" let ?tb = "snd ?sb" - from prems have nb: "numbound0 (snd(rsplit0 (Add a b)))" - by(cases "rsplit0 a",auto simp add: Let_def split_def) - have "Inum bs ((split (CN 0)) (rsplit0 (Add a b))) = - Inum bs ((split (CN 0)) ?sa)+Inum bs ((split (CN 0)) ?sb)" - by (simp add: Let_def split_def algebra_simps) - also have "\ = Inum bs a + Inum bs b" using prems by (cases "rsplit0 a", simp_all) - finally show ?case using nb by simp -qed(auto simp add: Let_def split_def algebra_simps , simp add: right_distrib[symmetric]) - - (* Linearize a formula*) -definition - lt :: "int \ num \ fm" -where - "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) - else (Gt (CN 0 (-c) (Neg t))))" - -definition - le :: "int \ num \ fm" -where - "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) - else (Ge (CN 0 (-c) (Neg t))))" - -definition - gt :: "int \ num \ fm" -where - "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) - else (Lt (CN 0 (-c) (Neg t))))" - -definition - ge :: "int \ num \ fm" -where - "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) - else (Le (CN 0 (-c) (Neg t))))" - -definition - eq :: "int \ num \ fm" -where - "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) - else (Eq (CN 0 (-c) (Neg t))))" - -definition - neq :: "int \ num \ fm" -where - "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) - else (NEq (CN 0 (-c) (Neg t))))" - -lemma lt: "numnoabs t \ Ifm bs (split lt (rsplit0 t)) = Ifm bs (Lt t) \ isrlfm (split lt (rsplit0 t))" -using rsplit0[where bs = "bs" and t="t"] -by (auto simp add: lt_def split_def,cases "snd(rsplit0 t)",auto,case_tac "nat",auto) - -lemma le: "numnoabs t \ Ifm bs (split le (rsplit0 t)) = Ifm bs (Le t) \ isrlfm (split le (rsplit0 t))" -using rsplit0[where bs = "bs" and t="t"] -by (auto simp add: le_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) - -lemma gt: "numnoabs t \ Ifm bs (split gt (rsplit0 t)) = Ifm bs (Gt t) \ isrlfm (split gt (rsplit0 t))" -using rsplit0[where bs = "bs" and t="t"] -by (auto simp add: gt_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) - -lemma ge: "numnoabs t \ Ifm bs (split ge (rsplit0 t)) = Ifm bs (Ge t) \ isrlfm (split ge (rsplit0 t))" -using rsplit0[where bs = "bs" and t="t"] -by (auto simp add: ge_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) - -lemma eq: "numnoabs t \ Ifm bs (split eq (rsplit0 t)) = Ifm bs (Eq t) \ isrlfm (split eq (rsplit0 t))" -using rsplit0[where bs = "bs" and t="t"] -by (auto simp add: eq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) - -lemma neq: "numnoabs t \ Ifm bs (split neq (rsplit0 t)) = Ifm bs (NEq t) \ isrlfm (split neq (rsplit0 t))" -using rsplit0[where bs = "bs" and t="t"] -by (auto simp add: neq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) - -lemma conj_lin: "isrlfm p \ isrlfm q \ isrlfm (conj p q)" -by (auto simp add: conj_def) -lemma disj_lin: "isrlfm p \ isrlfm q \ isrlfm (disj p q)" -by (auto simp add: disj_def) - -consts rlfm :: "fm \ fm" -recdef rlfm "measure fmsize" - "rlfm (And p q) = conj (rlfm p) (rlfm q)" - "rlfm (Or p q) = disj (rlfm p) (rlfm q)" - "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)" - "rlfm (Iff p q) = disj (conj (rlfm p) (rlfm q)) (conj (rlfm (NOT p)) (rlfm (NOT q)))" - "rlfm (Lt a) = split lt (rsplit0 a)" - "rlfm (Le a) = split le (rsplit0 a)" - "rlfm (Gt a) = split gt (rsplit0 a)" - "rlfm (Ge a) = split ge (rsplit0 a)" - "rlfm (Eq a) = split eq (rsplit0 a)" - "rlfm (NEq a) = split neq (rsplit0 a)" - "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))" - "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))" - "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))" - "rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))" - "rlfm (NOT (NOT p)) = rlfm p" - "rlfm (NOT T) = F" - "rlfm (NOT F) = T" - "rlfm (NOT (Lt a)) = rlfm (Ge a)" - "rlfm (NOT (Le a)) = rlfm (Gt a)" - "rlfm (NOT (Gt a)) = rlfm (Le a)" - "rlfm (NOT (Ge a)) = rlfm (Lt a)" - "rlfm (NOT (Eq a)) = rlfm (NEq a)" - "rlfm (NOT (NEq a)) = rlfm (Eq a)" - "rlfm p = p" (hints simp add: fmsize_pos) - -lemma rlfm_I: - assumes qfp: "qfree p" - shows "(Ifm bs (rlfm p) = Ifm bs p) \ isrlfm (rlfm p)" - using qfp -by (induct p rule: rlfm.induct, auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin) - - (* Operations needed for Ferrante and Rackoff *) -lemma rminusinf_inf: - assumes lp: "isrlfm p" - shows "\ z. \ x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\ z. \ x. ?P z x p") -using lp -proof (induct p rule: minusinf.induct) - case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto -next - case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto -next - case (3 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (Eq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp - thus ?case by blast -next - case (4 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (NEq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp - thus ?case by blast -next - case (5 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Lt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp - thus ?case by blast -next - case (6 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Le (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Le (CN 0 c e))" by simp - thus ?case by blast -next - case (7 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Gt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp - thus ?case by blast -next - case (8 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x < ?z" - hence "(real c * x < - ?e)" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) - hence "real c * x + ?e < 0" by arith - with xz have "?P ?z x (Ge (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp - thus ?case by blast -qed simp_all - -lemma rplusinf_inf: - assumes lp: "isrlfm p" - shows "\ z. \ x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\ z. \ x. ?P z x p") -using lp -proof (induct p rule: isrlfm.induct) - case (1 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto -next - case (2 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto -next - case (3 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (Eq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp - thus ?case by blast -next - case (4 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - hence "real c * x + ?e \ 0" by simp - with xz have "?P ?z x (NEq (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp - thus ?case by blast -next - case (5 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Lt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp - thus ?case by blast -next - case (6 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Le (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Le (CN 0 c e))" by simp - thus ?case by blast -next - case (7 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Gt (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp - thus ?case by blast -next - case (8 c e) - from prems have nb: "numbound0 e" by simp - from prems have cp: "real c > 0" by simp - fix a - let ?e="Inum (a#bs) e" - let ?z = "(- ?e) / real c" - {fix x - assume xz: "x > ?z" - with mult_strict_right_mono [OF xz cp] cp - have "(real c * x > - ?e)" by (simp add: mult_ac) - hence "real c * x + ?e > 0" by arith - with xz have "?P ?z x (Ge (CN 0 c e))" - using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } - hence "\ x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp - thus ?case by blast -qed simp_all - -lemma rminusinf_bound0: - assumes lp: "isrlfm p" - shows "bound0 (minusinf p)" - using lp - by (induct p rule: minusinf.induct) simp_all - -lemma rplusinf_bound0: - assumes lp: "isrlfm p" - shows "bound0 (plusinf p)" - using lp - by (induct p rule: plusinf.induct) simp_all - -lemma rminusinf_ex: - assumes lp: "isrlfm p" - and ex: "Ifm (a#bs) (minusinf p)" - shows "\ x. Ifm (x#bs) p" -proof- - from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex - have th: "\ x. Ifm (x#bs) (minusinf p)" by auto - from rminusinf_inf[OF lp, where bs="bs"] - obtain z where z_def: "\x x. Ifm (x#bs) p" -proof- - from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex - have th: "\ x. Ifm (x#bs) (plusinf p)" by auto - from rplusinf_inf[OF lp, where bs="bs"] - obtain z where z_def: "\x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast - from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp - moreover have "z + 1 > z" by simp - ultimately show ?thesis using z_def by auto -qed - -consts - uset:: "fm \ (num \ int) list" - usubst :: "fm \ (num \ int) \ fm " -recdef uset "measure size" - "uset (And p q) = (uset p @ uset q)" - "uset (Or p q) = (uset p @ uset q)" - "uset (Eq (CN 0 c e)) = [(Neg e,c)]" - "uset (NEq (CN 0 c e)) = [(Neg e,c)]" - "uset (Lt (CN 0 c e)) = [(Neg e,c)]" - "uset (Le (CN 0 c e)) = [(Neg e,c)]" - "uset (Gt (CN 0 c e)) = [(Neg e,c)]" - "uset (Ge (CN 0 c e)) = [(Neg e,c)]" - "uset p = []" -recdef usubst "measure size" - "usubst (And p q) = (\ (t,n). And (usubst p (t,n)) (usubst q (t,n)))" - "usubst (Or p q) = (\ (t,n). Or (usubst p (t,n)) (usubst q (t,n)))" - "usubst (Eq (CN 0 c e)) = (\ (t,n). Eq (Add (Mul c t) (Mul n e)))" - "usubst (NEq (CN 0 c e)) = (\ (t,n). NEq (Add (Mul c t) (Mul n e)))" - "usubst (Lt (CN 0 c e)) = (\ (t,n). Lt (Add (Mul c t) (Mul n e)))" - "usubst (Le (CN 0 c e)) = (\ (t,n). Le (Add (Mul c t) (Mul n e)))" - "usubst (Gt (CN 0 c e)) = (\ (t,n). Gt (Add (Mul c t) (Mul n e)))" - "usubst (Ge (CN 0 c e)) = (\ (t,n). Ge (Add (Mul c t) (Mul n e)))" - "usubst p = (\ (t,n). p)" - -lemma usubst_I: assumes lp: "isrlfm p" - and np: "real n > 0" and nbt: "numbound0 t" - shows "(Ifm (x#bs) (usubst p (t,n)) = Ifm (((Inum (x#bs) t)/(real n))#bs) p) \ bound0 (usubst p (t,n))" (is "(?I x (usubst p (t,n)) = ?I ?u p) \ ?B p" is "(_ = ?I (?t/?n) p) \ _" is "(_ = ?I (?N x t /_) p) \ _") - using lp -proof(induct p rule: usubst.induct) - case (5 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Lt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) < 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)" - by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) < 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (6 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Le (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" - by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) \ 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (7 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Gt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) > 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)" - by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) > 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (8 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - have "?I ?u (Ge (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" - by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) \ 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (3 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - from np have np: "real n \ 0" by simp - have "?I ?u (Eq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) = 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) = 0)" - by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) = 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -next - case (4 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+ - from np have np: "real n \ 0" by simp - have "?I ?u (NEq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \ 0)" - using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp - also have "\ = (?n*(real c *(?t/?n)) + ?n*(?N x e) \ 0)" - by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" - and b="0", simplified divide_zero_left]) (simp only: algebra_simps) - also have "\ = (real c *?t + ?n* (?N x e) \ 0)" - using np by simp - finally show ?case using nbt nb by (simp add: algebra_simps) -qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"] nth_pos2) - -lemma uset_l: - assumes lp: "isrlfm p" - shows "\ (t,k) \ set (uset p). numbound0 t \ k >0" -using lp -by(induct p rule: uset.induct,auto) - -lemma rminusinf_uset: - assumes lp: "isrlfm p" - and nmi: "\ (Ifm (a#bs) (minusinf p))" (is "\ (Ifm (a#bs) (?M p))") - and ex: "Ifm (x#bs) p" (is "?I x p") - shows "\ (s,m) \ set (uset p). x \ Inum (a#bs) s / real m" (is "\ (s,m) \ ?U p. x \ ?N a s / real m") -proof- - have "\ (s,m) \ set (uset p). real m * x \ Inum (a#bs) s " (is "\ (s,m) \ ?U p. real m *x \ ?N a s") - using lp nmi ex - by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2) - then obtain s m where smU: "(s,m) \ set (uset p)" and mx: "real m * x \ ?N a s" by blast - from uset_l[OF lp] smU have mp: "real m > 0" by auto - from pos_divide_le_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \ ?N a s / real m" - by (auto simp add: mult_commute) - thus ?thesis using smU by auto -qed - -lemma rplusinf_uset: - assumes lp: "isrlfm p" - and nmi: "\ (Ifm (a#bs) (plusinf p))" (is "\ (Ifm (a#bs) (?M p))") - and ex: "Ifm (x#bs) p" (is "?I x p") - shows "\ (s,m) \ set (uset p). x \ Inum (a#bs) s / real m" (is "\ (s,m) \ ?U p. x \ ?N a s / real m") -proof- - have "\ (s,m) \ set (uset p). real m * x \ Inum (a#bs) s " (is "\ (s,m) \ ?U p. real m *x \ ?N a s") - using lp nmi ex - by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2) - then obtain s m where smU: "(s,m) \ set (uset p)" and mx: "real m * x \ ?N a s" by blast - from uset_l[OF lp] smU have mp: "real m > 0" by auto - from pos_le_divide_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \ ?N a s / real m" - by (auto simp add: mult_commute) - thus ?thesis using smU by auto -qed - -lemma lin_dense: - assumes lp: "isrlfm p" - and noS: "\ t. l < t \ t< u \ t \ (\ (t,n). Inum (x#bs) t / real n) ` set (uset p)" - (is "\ t. _ \ _ \ t \ (\ (t,n). ?N x t / real n ) ` (?U p)") - and lx: "l < x" and xu:"x < u" and px:" Ifm (x#bs) p" - and ly: "l < y" and yu: "y < u" - shows "Ifm (y#bs) p" -using lp px noS -proof (induct p rule: isrlfm.induct) - case (5 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from prems have "x * real c + ?N x e < 0" by (simp add: algebra_simps) - hence pxc: "x < (- ?N x e) / real c" - by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y < (-?N x e)/ real c" - hence "y * real c < - ?N x e" - by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y > (- ?N x e) / real c" - with yu have eu: "u > (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ l" by (cases "(- ?N x e) / real c > l", auto) - with lx pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (6 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp + - from prems have "x * real c + ?N x e \ 0" by (simp add: algebra_simps) - hence pxc: "x \ (- ?N x e) / real c" - by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y < (-?N x e)/ real c" - hence "y * real c < - ?N x e" - by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y > (- ?N x e) / real c" - with yu have eu: "u > (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ l" by (cases "(- ?N x e) / real c > l", auto) - with lx pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (7 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from prems have "x * real c + ?N x e > 0" by (simp add: algebra_simps) - hence pxc: "x > (- ?N x e) / real c" - by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y > (-?N x e)/ real c" - hence "y * real c > - ?N x e" - by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y < (- ?N x e) / real c" - with ly have eu: "l < (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ u" by (cases "(- ?N x e) / real c > l", auto) - with xu pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (8 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from prems have "x * real c + ?N x e \ 0" by (simp add: algebra_simps) - hence pxc: "x \ (- ?N x e) / real c" - by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y < (- ?N x e) / real c \ y > (-?N x e) / real c" by auto - moreover {assume y: "y > (-?N x e)/ real c" - hence "y * real c > - ?N x e" - by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) - hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) - hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} - moreover {assume y: "y < (- ?N x e) / real c" - with ly have eu: "l < (- ?N x e) / real c" by auto - with noSc ly yu have "(- ?N x e) / real c \ u" by (cases "(- ?N x e) / real c > l", auto) - with xu pxc have "False" by auto - hence ?case by simp } - ultimately show ?case by blast -next - case (3 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from cp have cnz: "real c \ 0" by simp - from prems have "x * real c + ?N x e = 0" by (simp add: algebra_simps) - hence pxc: "x = (- ?N x e) / real c" - by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"]) - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with lx xu have yne: "x \ - ?N x e / real c" by auto - with pxc show ?case by simp -next - case (4 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ - from cp have cnz: "real c \ 0" by simp - from prems have noSc:"\ t. l < t \ t < u \ t \ (- ?N x e) / real c" by auto - with ly yu have yne: "y \ - ?N x e / real c" by auto - hence "y* real c \ -?N x e" - by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp - hence "y* real c + ?N x e \ 0" by (simp add: algebra_simps) - thus ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] - by (simp add: algebra_simps) -qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="y" and b'="x"]) - -lemma finite_set_intervals: - assumes px: "P (x::real)" - and lx: "l \ x" and xu: "x \ u" - and linS: "l\ S" and uinS: "u \ S" - and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" - shows "\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a \ x \ x \ b \ P x" -proof- - let ?Mx = "{y. y\ S \ y \ x}" - let ?xM = "{y. y\ S \ x \ y}" - let ?a = "Max ?Mx" - let ?b = "Min ?xM" - have MxS: "?Mx \ S" by blast - hence fMx: "finite ?Mx" using fS finite_subset by auto - from lx linS have linMx: "l \ ?Mx" by blast - hence Mxne: "?Mx \ {}" by blast - have xMS: "?xM \ S" by blast - hence fxM: "finite ?xM" using fS finite_subset by auto - from xu uinS have linxM: "u \ ?xM" by blast - hence xMne: "?xM \ {}" by blast - have ax:"?a \ x" using Mxne fMx by auto - have xb:"x \ ?b" using xMne fxM by auto - have "?a \ ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \ S" using MxS by blast - have "?b \ ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \ S" using xMS by blast - have noy:"\ y. ?a < y \ y < ?b \ y \ S" - proof(clarsimp) - fix y - assume ay: "?a < y" and yb: "y < ?b" and yS: "y \ S" - from yS have "y\ ?Mx \ y\ ?xM" by auto - moreover {assume "y \ ?Mx" hence "y \ ?a" using Mxne fMx by auto with ay have "False" by simp} - moreover {assume "y \ ?xM" hence "y \ ?b" using xMne fxM by auto with yb have "False" by simp} - ultimately show "False" by blast - qed - from ainS binS noy ax xb px show ?thesis by blast -qed - -lemma finite_set_intervals2: - assumes px: "P (x::real)" - and lx: "l \ x" and xu: "x \ u" - and linS: "l\ S" and uinS: "u \ S" - and fS:"finite S" and lS: "\ x\ S. l \ x" and Su: "\ x\ S. x \ u" - shows "(\ s\ S. P s) \ (\ a \ S. \ b \ S. (\ y. a < y \ y < b \ y \ S) \ a < x \ x < b \ P x)" -proof- - from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su] - obtain a and b where - as: "a\ S" and bs: "b\ S" and noS:"\y. a < y \ y < b \ y \ S" and axb: "a \ x \ x \ b \ P x" by auto - from axb have "x= a \ x= b \ (a < x \ x < b)" by auto - thus ?thesis using px as bs noS by blast -qed - -lemma rinf_uset: - assumes lp: "isrlfm p" - and nmi: "\ (Ifm (x#bs) (minusinf p))" (is "\ (Ifm (x#bs) (?M p))") - and npi: "\ (Ifm (x#bs) (plusinf p))" (is "\ (Ifm (x#bs) (?P p))") - and ex: "\ x. Ifm (x#bs) p" (is "\ x. ?I x p") - shows "\ (l,n) \ set (uset p). \ (s,m) \ set (uset p). ?I ((Inum (x#bs) l / real n + Inum (x#bs) s / real m) / 2) p" -proof- - let ?N = "\ x t. Inum (x#bs) t" - let ?U = "set (uset p)" - from ex obtain a where pa: "?I a p" by blast - from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi - have nmi': "\ (?I a (?M p))" by simp - from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi - have npi': "\ (?I a (?P p))" by simp - have "\ (l,n) \ set (uset p). \ (s,m) \ set (uset p). ?I ((?N a l/real n + ?N a s /real m) / 2) p" - proof- - let ?M = "(\ (t,c). ?N a t / real c) ` ?U" - have fM: "finite ?M" by auto - from rminusinf_uset[OF lp nmi pa] rplusinf_uset[OF lp npi pa] - have "\ (l,n) \ set (uset p). \ (s,m) \ set (uset p). a \ ?N x l / real n \ a \ ?N x s / real m" by blast - then obtain "t" "n" "s" "m" where - tnU: "(t,n) \ ?U" and smU: "(s,m) \ ?U" - and xs1: "a \ ?N x s / real m" and tx1: "a \ ?N x t / real n" by blast - from uset_l[OF lp] tnU smU numbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 have xs: "a \ ?N a s / real m" and tx: "a \ ?N a t / real n" by auto - from tnU have Mne: "?M \ {}" by auto - hence Une: "?U \ {}" by simp - let ?l = "Min ?M" - let ?u = "Max ?M" - have linM: "?l \ ?M" using fM Mne by simp - have uinM: "?u \ ?M" using fM Mne by simp - have tnM: "?N a t / real n \ ?M" using tnU by auto - have smM: "?N a s / real m \ ?M" using smU by auto - have lM: "\ t\ ?M. ?l \ t" using Mne fM by auto - have Mu: "\ t\ ?M. t \ ?u" using Mne fM by auto - have "?l \ ?N a t / real n" using tnM Mne by simp hence lx: "?l \ a" using tx by simp - have "?N a s / real m \ ?u" using smM Mne by simp hence xu: "a \ ?u" using xs by simp - from finite_set_intervals2[where P="\ x. ?I x p",OF pa lx xu linM uinM fM lM Mu] - have "(\ s\ ?M. ?I s p) \ - (\ t1\ ?M. \ t2 \ ?M. (\ y. t1 < y \ y < t2 \ y \ ?M) \ t1 < a \ a < t2 \ ?I a p)" . - moreover { fix u assume um: "u\ ?M" and pu: "?I u p" - hence "\ (tu,nu) \ ?U. u = ?N a tu / real nu" by auto - then obtain "tu" "nu" where tuU: "(tu,nu) \ ?U" and tuu:"u= ?N a tu / real nu" by blast - have "(u + u) / 2 = u" by auto with pu tuu - have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" by simp - with tuU have ?thesis by blast} - moreover{ - assume "\ t1\ ?M. \ t2 \ ?M. (\ y. t1 < y \ y < t2 \ y \ ?M) \ t1 < a \ a < t2 \ ?I a p" - then obtain t1 and t2 where t1M: "t1 \ ?M" and t2M: "t2\ ?M" - and noM: "\ y. t1 < y \ y < t2 \ y \ ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p" - by blast - from t1M have "\ (t1u,t1n) \ ?U. t1 = ?N a t1u / real t1n" by auto - then obtain "t1u" "t1n" where t1uU: "(t1u,t1n) \ ?U" and t1u: "t1 = ?N a t1u / real t1n" by blast - from t2M have "\ (t2u,t2n) \ ?U. t2 = ?N a t2u / real t2n" by auto - then obtain "t2u" "t2n" where t2uU: "(t2u,t2n) \ ?U" and t2u: "t2 = ?N a t2u / real t2n" by blast - from t1x xt2 have t1t2: "t1 < t2" by simp - let ?u = "(t1 + t2) / 2" - from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto - from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" . - with t1uU t2uU t1u t2u have ?thesis by blast} - ultimately show ?thesis by blast - qed - then obtain "l" "n" "s" "m" where lnU: "(l,n) \ ?U" and smU:"(s,m) \ ?U" - and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" by blast - from lnU smU uset_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" by auto - from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] - numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu - have "?I ((?N x l / real n + ?N x s / real m) / 2) p" by simp - with lnU smU - show ?thesis by auto -qed - (* The Ferrante - Rackoff Theorem *) - -theorem fr_eq: - assumes lp: "isrlfm p" - shows "(\ x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \ (Ifm (x#bs) (plusinf p)) \ (\ (t,n) \ set (uset p). \ (s,m) \ set (uset p). Ifm ((((Inum (x#bs) t)/ real n + (Inum (x#bs) s) / real m) /2)#bs) p))" - (is "(\ x. ?I x p) = (?M \ ?P \ ?F)" is "?E = ?D") -proof - assume px: "\ x. ?I x p" - have "?M \ ?P \ (\ ?M \ \ ?P)" by blast - moreover {assume "?M \ ?P" hence "?D" by blast} - moreover {assume nmi: "\ ?M" and npi: "\ ?P" - from rinf_uset[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast} - ultimately show "?D" by blast -next - assume "?D" - moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} - moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } - moreover {assume f:"?F" hence "?E" by blast} - ultimately show "?E" by blast -qed - - -lemma fr_equsubst: - assumes lp: "isrlfm p" - shows "(\ x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \ (Ifm (x#bs) (plusinf p)) \ (\ (t,k) \ set (uset p). \ (s,l) \ set (uset p). Ifm (x#bs) (usubst p (Add(Mul l t) (Mul k s) , 2*k*l))))" - (is "(\ x. ?I x p) = (?M \ ?P \ ?F)" is "?E = ?D") -proof - assume px: "\ x. ?I x p" - have "?M \ ?P \ (\ ?M \ \ ?P)" by blast - moreover {assume "?M \ ?P" hence "?D" by blast} - moreover {assume nmi: "\ ?M" and npi: "\ ?P" - let ?f ="\ (t,n). Inum (x#bs) t / real n" - let ?N = "\ t. Inum (x#bs) t" - {fix t n s m assume "(t,n)\ set (uset p)" and "(s,m) \ set (uset p)" - with uset_l[OF lp] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0" - by auto - let ?st = "Add (Mul m t) (Mul n s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute) - from tnb snb have st_nb: "numbound0 ?st" by simp - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mnp mp np by (simp add: algebra_simps add_divide_distrib) - from usubst_I[OF lp mnp st_nb, where x="x" and bs="bs"] - have "?I x (usubst p (?st,2*n*m)) = ?I ((?N t / real n + ?N s / real m) /2) p" by (simp only: st[symmetric])} - with rinf_uset[OF lp nmi npi px] have "?F" by blast hence "?D" by blast} - ultimately show "?D" by blast -next - assume "?D" - moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} - moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } - moreover {fix t k s l assume "(t,k) \ set (uset p)" and "(s,l) \ set (uset p)" - and px:"?I x (usubst p (Add (Mul l t) (Mul k s), 2*k*l))" - with uset_l[OF lp] have tnb: "numbound0 t" and np:"real k > 0" and snb: "numbound0 s" and mp:"real l > 0" by auto - let ?st = "Add (Mul l t) (Mul k s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*k*l) > 0" - by (simp add: mult_commute) - from tnb snb have st_nb: "numbound0 ?st" by simp - from usubst_I[OF lp mnp st_nb, where bs="bs"] px have "?E" by auto} - ultimately show "?E" by blast -qed - - - (* Implement the right hand side of Ferrante and Rackoff's Theorem. *) -constdefs ferrack:: "fm \ fm" - "ferrack p \ (let p' = rlfm (simpfm p); mp = minusinf p'; pp = plusinf p' - in if (mp = T \ pp = T) then T else - (let U = remdps(map simp_num_pair - (map (\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) - (alluopairs (uset p')))) - in decr (disj mp (disj pp (evaldjf (simpfm o (usubst p')) U)))))" - -lemma uset_cong_aux: - assumes Ul: "\ (t,n) \ set U. numbound0 t \ n >0" - shows "((\ (t,n). Inum (x#bs) t /real n) ` (set (map (\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) (alluopairs U)))) = ((\ ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (set U \ set U))" - (is "?lhs = ?rhs") -proof(auto) - fix t n s m - assume "((t,n),(s,m)) \ set (alluopairs U)" - hence th: "((t,n),(s,m)) \ (set U \ set U)" - using alluopairs_set1[where xs="U"] by blast - let ?N = "\ t. Inum (x#bs) t" - let ?st= "Add (Mul m t) (Mul n s)" - from Ul th have mnz: "m \ 0" by auto - from Ul th have nnz: "n \ 0" by auto - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mnz nnz by (simp add: algebra_simps add_divide_distrib) - - thus "(real m * Inum (x # bs) t + real n * Inum (x # bs) s) / - (2 * real n * real m) - \ (\((t, n), s, m). - (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` - (set U \ set U)"using mnz nnz th - apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def) - by (rule_tac x="(s,m)" in bexI,simp_all) - (rule_tac x="(t,n)" in bexI,simp_all) -next - fix t n s m - assume tnU: "(t,n) \ set U" and smU:"(s,m) \ set U" - let ?N = "\ t. Inum (x#bs) t" - let ?st= "Add (Mul m t) (Mul n s)" - from Ul smU have mnz: "m \ 0" by auto - from Ul tnU have nnz: "n \ 0" by auto - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mnz nnz by (simp add: algebra_simps add_divide_distrib) - let ?P = "\ (t',n') (s',m'). (Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" - have Pc:"\ a b. ?P a b = ?P b a" - by auto - from Ul alluopairs_set1 have Up:"\ ((t,n),(s,m)) \ set (alluopairs U). n \ 0 \ m \ 0" by blast - from alluopairs_ex[OF Pc, where xs="U"] tnU smU - have th':"\ ((t',n'),(s',m')) \ set (alluopairs U). ?P (t',n') (s',m')" - by blast - then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \ set (alluopairs U)" - and Pts': "?P (t',n') (s',m')" by blast - from ts'_U Up have mnz': "m' \ 0" and nnz': "n'\ 0" by auto - let ?st' = "Add (Mul m' t') (Mul n' s')" - have st': "(?N t' / real n' + ?N s' / real m')/2 = ?N ?st' / real (2*n'*m')" - using mnz' nnz' by (simp add: algebra_simps add_divide_distrib) - from Pts' have - "(Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" by simp - also have "\ = ((\(t, n). Inum (x # bs) t / real n) ((\((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ((t',n'),(s',m'))))" by (simp add: st') - finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2 - \ (\(t, n). Inum (x # bs) t / real n) ` - (\((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ` - set (alluopairs U)" - using ts'_U by blast -qed - -lemma uset_cong: - assumes lp: "isrlfm p" - and UU': "((\ (t,n). Inum (x#bs) t /real n) ` U') = ((\ ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (U \ U))" (is "?f ` U' = ?g ` (U\U)") - and U: "\ (t,n) \ U. numbound0 t \ n > 0" - and U': "\ (t,n) \ U'. numbound0 t \ n > 0" - shows "(\ (t,n) \ U. \ (s,m) \ U. Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))) = (\ (t,n) \ U'. Ifm (x#bs) (usubst p (t,n)))" - (is "?lhs = ?rhs") -proof - assume ?lhs - then obtain t n s m where tnU: "(t,n) \ U" and smU:"(s,m) \ U" and - Pst: "Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))" by blast - let ?N = "\ t. Inum (x#bs) t" - from tnU smU U have tnb: "numbound0 t" and np: "n > 0" - and snb: "numbound0 s" and mp:"m > 0" by auto - let ?st= "Add (Mul m t) (Mul n s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) - from tnb snb have stnb: "numbound0 ?st" by simp - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mp np by (simp add: algebra_simps add_divide_distrib) - from tnU smU UU' have "?g ((t,n),(s,m)) \ ?f ` U'" by blast - hence "\ (t',n') \ U'. ?g ((t,n),(s,m)) = ?f (t',n')" - by auto (rule_tac x="(a,b)" in bexI, auto) - then obtain t' n' where tnU': "(t',n') \ U'" and th: "?g ((t,n),(s,m)) = ?f (t',n')" by blast - from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto - from usubst_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst - have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp - from conjunct1[OF usubst_I[OF lp np' tnb', where bs="bs" and x="x"], symmetric] th[simplified split_def fst_conv snd_conv,symmetric] Pst2[simplified st[symmetric]] - have "Ifm (x # bs) (usubst p (t', n')) " by (simp only: st) - then show ?rhs using tnU' by auto -next - assume ?rhs - then obtain t' n' where tnU': "(t',n') \ U'" and Pt': "Ifm (x # bs) (usubst p (t', n'))" - by blast - from tnU' UU' have "?f (t',n') \ ?g ` (U\U)" by blast - hence "\ ((t,n),(s,m)) \ (U\U). ?f (t',n') = ?g ((t,n),(s,m))" - by auto (rule_tac x="(a,b)" in bexI, auto) - then obtain t n s m where tnU: "(t,n) \ U" and smU:"(s,m) \ U" and - th: "?f (t',n') = ?g((t,n),(s,m)) "by blast - let ?N = "\ t. Inum (x#bs) t" - from tnU smU U have tnb: "numbound0 t" and np: "n > 0" - and snb: "numbound0 s" and mp:"m > 0" by auto - let ?st= "Add (Mul m t) (Mul n s)" - from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" - by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) - from tnb snb have stnb: "numbound0 ?st" by simp - have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" - using mp np by (simp add: algebra_simps add_divide_distrib) - from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto - from usubst_I[OF lp np' tnb', where bs="bs" and x="x",simplified th[simplified split_def fst_conv snd_conv] st] Pt' - have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp - with usubst_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU show ?lhs by blast -qed - -lemma ferrack: - assumes qf: "qfree p" - shows "qfree (ferrack p) \ ((Ifm bs (ferrack p)) = (\ x. Ifm (x#bs) p))" - (is "_ \ (?rhs = ?lhs)") -proof- - let ?I = "\ x p. Ifm (x#bs) p" - fix x - let ?N = "\ t. Inum (x#bs) t" - let ?q = "rlfm (simpfm p)" - let ?U = "uset ?q" - let ?Up = "alluopairs ?U" - let ?g = "\ ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)" - let ?S = "map ?g ?Up" - let ?SS = "map simp_num_pair ?S" - let ?Y = "remdps ?SS" - let ?f= "(\ (t,n). ?N t / real n)" - let ?h = "\ ((t,n),(s,m)). (?N t/real n + ?N s/ real m) /2" - let ?F = "\ p. \ a \ set (uset p). \ b \ set (uset p). ?I x (usubst p (?g(a,b)))" - let ?ep = "evaldjf (simpfm o (usubst ?q)) ?Y" - from rlfm_I[OF simpfm_qf[OF qf]] have lq: "isrlfm ?q" by blast - from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \ (set ?U \ set ?U)" by simp - from uset_l[OF lq] have U_l: "\ (t,n) \ set ?U. numbound0 t \ n > 0" . - from U_l UpU - have "\ ((t,n),(s,m)) \ set ?Up. numbound0 t \ n> 0 \ numbound0 s \ m > 0" by auto - hence Snb: "\ (t,n) \ set ?S. numbound0 t \ n > 0 " - by (auto simp add: mult_pos_pos) - have Y_l: "\ (t,n) \ set ?Y. numbound0 t \ n > 0" - proof- - { fix t n assume tnY: "(t,n) \ set ?Y" - hence "(t,n) \ set ?SS" by simp - hence "\ (t',n') \ set ?S. simp_num_pair (t',n') = (t,n)" - by (auto simp add: split_def) (rule_tac x="((aa,ba),(ab,bb))" in bexI, simp_all) - then obtain t' n' where tn'S: "(t',n') \ set ?S" and tns: "simp_num_pair (t',n') = (t,n)" by blast - from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" by auto - from simp_num_pair_l[OF tnb np tns] - have "numbound0 t \ n > 0" . } - thus ?thesis by blast - qed - - have YU: "(?f ` set ?Y) = (?h ` (set ?U \ set ?U))" - proof- - from simp_num_pair_ci[where bs="x#bs"] have - "\x. (?f o simp_num_pair) x = ?f x" by auto - hence th: "?f o simp_num_pair = ?f" using ext by blast - have "(?f ` set ?Y) = ((?f o simp_num_pair) ` set ?S)" by (simp add: image_compose) - also have "\ = (?f ` set ?S)" by (simp add: th) - also have "\ = ((?f o ?g) ` set ?Up)" - by (simp only: set_map o_def image_compose[symmetric]) - also have "\ = (?h ` (set ?U \ set ?U))" - using uset_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_compose[symmetric]] by blast - finally show ?thesis . - qed - have "\ (t,n) \ set ?Y. bound0 (simpfm (usubst ?q (t,n)))" - proof- - { fix t n assume tnY: "(t,n) \ set ?Y" - with Y_l have tnb: "numbound0 t" and np: "real n > 0" by auto - from usubst_I[OF lq np tnb] - have "bound0 (usubst ?q (t,n))" by simp hence "bound0 (simpfm (usubst ?q (t,n)))" - using simpfm_bound0 by simp} - thus ?thesis by blast - qed - hence ep_nb: "bound0 ?ep" using evaldjf_bound0[where xs="?Y" and f="simpfm o (usubst ?q)"] by auto - let ?mp = "minusinf ?q" - let ?pp = "plusinf ?q" - let ?M = "?I x ?mp" - let ?P = "?I x ?pp" - let ?res = "disj ?mp (disj ?pp ?ep)" - from rminusinf_bound0[OF lq] rplusinf_bound0[OF lq] ep_nb - have nbth: "bound0 ?res" by auto - - from conjunct1[OF rlfm_I[OF simpfm_qf[OF qf]]] simpfm - - have th: "?lhs = (\ x. ?I x ?q)" by auto - from th fr_equsubst[OF lq, where bs="bs" and x="x"] have lhfr: "?lhs = (?M \ ?P \ ?F ?q)" - by (simp only: split_def fst_conv snd_conv) - also have "\ = (?M \ ?P \ (\ (t,n) \ set ?Y. ?I x (simpfm (usubst ?q (t,n)))))" - using uset_cong[OF lq YU U_l Y_l] by (simp only: split_def fst_conv snd_conv simpfm) - also have "\ = (Ifm (x#bs) ?res)" - using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="simpfm o (usubst ?q)",symmetric] - by (simp add: split_def pair_collapse) - finally have lheq: "?lhs = (Ifm bs (decr ?res))" using decr[OF nbth] by blast - hence lr: "?lhs = ?rhs" apply (unfold ferrack_def Let_def) - by (cases "?mp = T \ ?pp = T", auto) (simp add: disj_def)+ - from decr_qf[OF nbth] have "qfree (ferrack p)" by (auto simp add: Let_def ferrack_def) - with lr show ?thesis by blast -qed - -definition linrqe:: "fm \ fm" where - "linrqe p = qelim (prep p) ferrack" - -theorem linrqe: "Ifm bs (linrqe p) = Ifm bs p \ qfree (linrqe p)" -using ferrack qelim_ci prep -unfolding linrqe_def by auto - -definition ferrack_test :: "unit \ fm" where - "ferrack_test u = linrqe (A (A (Imp (Lt (Sub (Bound 1) (Bound 0))) - (E (Eq (Sub (Add (Bound 0) (Bound 2)) (Bound 1)))))))" - -ML {* @{code ferrack_test} () *} - -oracle linr_oracle = {* -let - -fun num_of_term vs (t as Free (xn, xT)) = (case AList.lookup (op =) vs t - of NONE => error "Variable not found in the list!" - | SOME n => @{code Bound} n) - | num_of_term vs @{term "real (0::int)"} = @{code C} 0 - | num_of_term vs @{term "real (1::int)"} = @{code C} 1 - | num_of_term vs @{term "0::real"} = @{code C} 0 - | num_of_term vs @{term "1::real"} = @{code C} 1 - | num_of_term vs (Bound i) = @{code Bound} i - | num_of_term vs (@{term "uminus :: real \ real"} $ t') = @{code Neg} (num_of_term vs t') - | num_of_term vs (@{term "op + :: real \ real \ real"} $ t1 $ t2) = @{code Add} (num_of_term vs t1, num_of_term vs t2) - | num_of_term vs (@{term "op - :: real \ real \ real"} $ t1 $ t2) = @{code Sub} (num_of_term vs t1, num_of_term vs t2) - | num_of_term vs (@{term "op * :: real \ real \ real"} $ t1 $ t2) = (case (num_of_term vs t1) - of @{code C} i => @{code Mul} (i, num_of_term vs t2) - | _ => error "num_of_term: unsupported Multiplication") - | num_of_term vs (@{term "real :: int \ real"} $ (@{term "number_of :: int \ int"} $ t')) = @{code C} (HOLogic.dest_numeral t') - | num_of_term vs (@{term "number_of :: int \ real"} $ t') = @{code C} (HOLogic.dest_numeral t') - | num_of_term vs t = error ("num_of_term: unknown term " ^ Syntax.string_of_term @{context} t); - -fun fm_of_term vs @{term True} = @{code T} - | fm_of_term vs @{term False} = @{code F} - | fm_of_term vs (@{term "op < :: real \ real \ bool"} $ t1 $ t2) = @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term vs (@{term "op \ :: real \ real \ bool"} $ t1 $ t2) = @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term vs (@{term "op = :: real \ real \ bool"} $ t1 $ t2) = @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term vs (@{term "op \ :: bool \ bool \ bool"} $ t1 $ t2) = @{code Iff} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "op &"} $ t1 $ t2) = @{code And} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "op |"} $ t1 $ t2) = @{code Or} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "op -->"} $ t1 $ t2) = @{code Imp} (fm_of_term vs t1, fm_of_term vs t2) - | fm_of_term vs (@{term "Not"} $ t') = @{code NOT} (fm_of_term vs t') - | fm_of_term vs (Const ("Ex", _) $ Abs (xn, xT, p)) = - @{code E} (fm_of_term (map (fn (v, n) => (v, n + 1)) vs) p) - | fm_of_term vs (Const ("All", _) $ Abs (xn, xT, p)) = - @{code A} (fm_of_term (map (fn (v, n) => (v, n + 1)) vs) p) - | fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); - -fun term_of_num vs (@{code C} i) = @{term "real :: int \ real"} $ HOLogic.mk_number HOLogic.intT i - | term_of_num vs (@{code Bound} n) = fst (the (find_first (fn (_, m) => n = m) vs)) - | term_of_num vs (@{code Neg} t') = @{term "uminus :: real \ real"} $ term_of_num vs t' - | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \ real \ real"} $ - term_of_num vs t1 $ term_of_num vs t2 - | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \ real \ real"} $ - term_of_num vs t1 $ term_of_num vs t2 - | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \ real \ real"} $ - term_of_num vs (@{code C} i) $ term_of_num vs t2 - | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)); - -fun term_of_fm vs @{code T} = HOLogic.true_const - | term_of_fm vs @{code F} = HOLogic.false_const - | term_of_fm vs (@{code Lt} t) = @{term "op < :: real \ real \ bool"} $ - term_of_num vs t $ @{term "0::real"} - | term_of_fm vs (@{code Le} t) = @{term "op \ :: real \ real \ bool"} $ - term_of_num vs t $ @{term "0::real"} - | term_of_fm vs (@{code Gt} t) = @{term "op < :: real \ real \ bool"} $ - @{term "0::real"} $ term_of_num vs t - | term_of_fm vs (@{code Ge} t) = @{term "op \ :: real \ real \ bool"} $ - @{term "0::real"} $ term_of_num vs t - | term_of_fm vs (@{code Eq} t) = @{term "op = :: real \ real \ bool"} $ - term_of_num vs t $ @{term "0::real"} - | term_of_fm vs (@{code NEq} t) = term_of_fm vs (@{code NOT} (@{code Eq} t)) - | term_of_fm vs (@{code NOT} t') = HOLogic.Not $ term_of_fm vs t' - | term_of_fm vs (@{code And} (t1, t2)) = HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs (@{code Or} (t1, t2)) = HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs (@{code Imp} (t1, t2)) = HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs (@{code Iff} (t1, t2)) = @{term "op \ :: bool \ bool \ bool"} $ - term_of_fm vs t1 $ term_of_fm vs t2 - | term_of_fm vs _ = error "If this is raised, Isabelle/HOL or generate_code is inconsistent."; - -in fn ct => - let - val thy = Thm.theory_of_cterm ct; - val t = Thm.term_of ct; - val fs = OldTerm.term_frees t; - val vs = fs ~~ (0 upto (length fs - 1)); - val res = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, term_of_fm vs (@{code linrqe} (fm_of_term vs t)))); - in Thm.cterm_of thy res end -end; -*} - -use "linrtac.ML" -setup LinrTac.setup - -lemma - fixes x :: real - shows "2 * x \ 2 * x \ 2 * x \ 2 * x + 1" -apply rferrack -done - -lemma - fixes x :: real - shows "\y \ x. x = y + 1" -apply rferrack -done - -lemma - fixes x :: real - shows "\ (\z. x + z = x + z + 1)" -apply rferrack -done - -end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/Reflected_Presburger.thy --- a/src/HOL/ex/Reflected_Presburger.thy Tue Feb 03 16:50:40 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2176 +0,0 @@ -(* Title: HOL/ex/Reflected_Presburger.thy - Author: Amine Chaieb -*) - -theory Reflected_Presburger -imports Main GCD Efficient_Nat -uses ("coopertac.ML") -begin - -function - iupt :: "int \ int \ int list" -where - "iupt i j = (if j < i then [] else i # iupt (i+1) j)" -by pat_completeness auto -termination by (relation "measure (\ (i, j). nat (j-i+1))") auto - -lemma iupt_set: "set (iupt i j) = {i..j}" - by (induct rule: iupt.induct) (simp add: simp_from_to) - -(* Periodicity of dvd *) - - (*********************************************************************************) - (**** SHADOW SYNTAX AND SEMANTICS ****) - (*********************************************************************************) - -datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num - | Mul int num - - (* A size for num to make inductive proofs simpler*) -primrec num_size :: "num \ nat" where - "num_size (C c) = 1" -| "num_size (Bound n) = 1" -| "num_size (Neg a) = 1 + num_size a" -| "num_size (Add a b) = 1 + num_size a + num_size b" -| "num_size (Sub a b) = 3 + num_size a + num_size b" -| "num_size (CN n c a) = 4 + num_size a" -| "num_size (Mul c a) = 1 + num_size a" - -primrec Inum :: "int list \ num \ int" where - "Inum bs (C c) = c" -| "Inum bs (Bound n) = bs!n" -| "Inum bs (CN n c a) = c * (bs!n) + (Inum bs a)" -| "Inum bs (Neg a) = -(Inum bs a)" -| "Inum bs (Add a b) = Inum bs a + Inum bs b" -| "Inum bs (Sub a b) = Inum bs a - Inum bs b" -| "Inum bs (Mul c a) = c* Inum bs a" - -datatype fm = - T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num| - NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm - | Closed nat | NClosed nat - - - (* A size for fm *) -consts fmsize :: "fm \ nat" -recdef fmsize "measure size" - "fmsize (NOT p) = 1 + fmsize p" - "fmsize (And p q) = 1 + fmsize p + fmsize q" - "fmsize (Or p q) = 1 + fmsize p + fmsize q" - "fmsize (Imp p q) = 3 + fmsize p + fmsize q" - "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" - "fmsize (E p) = 1 + fmsize p" - "fmsize (A p) = 4+ fmsize p" - "fmsize (Dvd i t) = 2" - "fmsize (NDvd i t) = 2" - "fmsize p = 1" - (* several lemmas about fmsize *) -lemma fmsize_pos: "fmsize p > 0" -by (induct p rule: fmsize.induct) simp_all - - (* Semantics of formulae (fm) *) -consts Ifm ::"bool list \ int list \ fm \ bool" -primrec - "Ifm bbs bs T = True" - "Ifm bbs bs F = False" - "Ifm bbs bs (Lt a) = (Inum bs a < 0)" - "Ifm bbs bs (Gt a) = (Inum bs a > 0)" - "Ifm bbs bs (Le a) = (Inum bs a \ 0)" - "Ifm bbs bs (Ge a) = (Inum bs a \ 0)" - "Ifm bbs bs (Eq a) = (Inum bs a = 0)" - "Ifm bbs bs (NEq a) = (Inum bs a \ 0)" - "Ifm bbs bs (Dvd i b) = (i dvd Inum bs b)" - "Ifm bbs bs (NDvd i b) = (\(i dvd Inum bs b))" - "Ifm bbs bs (NOT p) = (\ (Ifm bbs bs p))" - "Ifm bbs bs (And p q) = (Ifm bbs bs p \ Ifm bbs bs q)" - "Ifm bbs bs (Or p q) = (Ifm bbs bs p \ Ifm bbs bs q)" - "Ifm bbs bs (Imp p q) = ((Ifm bbs bs p) \ (Ifm bbs bs q))" - "Ifm bbs bs (Iff p q) = (Ifm bbs bs p = Ifm bbs bs q)" - "Ifm bbs bs (E p) = (\ x. Ifm bbs (x#bs) p)" - "Ifm bbs bs (A p) = (\ x. Ifm bbs (x#bs) p)" - "Ifm bbs bs (Closed n) = bbs!n" - "Ifm bbs bs (NClosed n) = (\ bbs!n)" - -consts prep :: "fm \ fm" -recdef prep "measure fmsize" - "prep (E T) = T" - "prep (E F) = F" - "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))" - "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))" - "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" - "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))" - "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" - "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" - "prep (E p) = E (prep p)" - "prep (A (And p q)) = And (prep (A p)) (prep (A q))" - "prep (A p) = prep (NOT (E (NOT p)))" - "prep (NOT (NOT p)) = prep p" - "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))" - "prep (NOT (A p)) = prep (E (NOT p))" - "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))" - "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))" - "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))" - "prep (NOT p) = NOT (prep p)" - "prep (Or p q) = Or (prep p) (prep q)" - "prep (And p q) = And (prep p) (prep q)" - "prep (Imp p q) = prep (Or (NOT p) q)" - "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))" - "prep p = p" -(hints simp add: fmsize_pos) -lemma prep: "Ifm bbs bs (prep p) = Ifm bbs bs p" -by (induct p arbitrary: bs rule: prep.induct, auto) - - - (* Quantifier freeness *) -consts qfree:: "fm \ bool" -recdef qfree "measure size" - "qfree (E p) = False" - "qfree (A p) = False" - "qfree (NOT p) = qfree p" - "qfree (And p q) = (qfree p \ qfree q)" - "qfree (Or p q) = (qfree p \ qfree q)" - "qfree (Imp p q) = (qfree p \ qfree q)" - "qfree (Iff p q) = (qfree p \ qfree q)" - "qfree p = True" - - (* Boundedness and substitution *) -consts - numbound0:: "num \ bool" (* a num is INDEPENDENT of Bound 0 *) - bound0:: "fm \ bool" (* A Formula is independent of Bound 0 *) - subst0:: "num \ fm \ fm" (* substitue a num into a formula for Bound 0 *) -primrec - "numbound0 (C c) = True" - "numbound0 (Bound n) = (n>0)" - "numbound0 (CN n i a) = (n >0 \ numbound0 a)" - "numbound0 (Neg a) = numbound0 a" - "numbound0 (Add a b) = (numbound0 a \ numbound0 b)" - "numbound0 (Sub a b) = (numbound0 a \ numbound0 b)" - "numbound0 (Mul i a) = numbound0 a" - -lemma numbound0_I: - assumes nb: "numbound0 a" - shows "Inum (b#bs) a = Inum (b'#bs) a" -using nb -by (induct a rule: numbound0.induct) (auto simp add: gr0_conv_Suc) - -primrec - "bound0 T = True" - "bound0 F = True" - "bound0 (Lt a) = numbound0 a" - "bound0 (Le a) = numbound0 a" - "bound0 (Gt a) = numbound0 a" - "bound0 (Ge a) = numbound0 a" - "bound0 (Eq a) = numbound0 a" - "bound0 (NEq a) = numbound0 a" - "bound0 (Dvd i a) = numbound0 a" - "bound0 (NDvd i a) = numbound0 a" - "bound0 (NOT p) = bound0 p" - "bound0 (And p q) = (bound0 p \ bound0 q)" - "bound0 (Or p q) = (bound0 p \ bound0 q)" - "bound0 (Imp p q) = ((bound0 p) \ (bound0 q))" - "bound0 (Iff p q) = (bound0 p \ bound0 q)" - "bound0 (E p) = False" - "bound0 (A p) = False" - "bound0 (Closed P) = True" - "bound0 (NClosed P) = True" -lemma bound0_I: - assumes bp: "bound0 p" - shows "Ifm bbs (b#bs) p = Ifm bbs (b'#bs) p" -using bp numbound0_I[where b="b" and bs="bs" and b'="b'"] -by (induct p rule: bound0.induct) (auto simp add: gr0_conv_Suc) - -fun numsubst0:: "num \ num \ num" where - "numsubst0 t (C c) = (C c)" -| "numsubst0 t (Bound n) = (if n=0 then t else Bound n)" -| "numsubst0 t (CN 0 i a) = Add (Mul i t) (numsubst0 t a)" -| "numsubst0 t (CN n i a) = CN n i (numsubst0 t a)" -| "numsubst0 t (Neg a) = Neg (numsubst0 t a)" -| "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)" -| "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)" -| "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)" - -lemma numsubst0_I: - "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t" -by (induct t rule: numsubst0.induct,auto simp:nth_Cons') - -lemma numsubst0_I': - "numbound0 a \ Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t" -by (induct t rule: numsubst0.induct, auto simp: nth_Cons' numbound0_I[where b="b" and b'="b'"]) - -primrec - "subst0 t T = T" - "subst0 t F = F" - "subst0 t (Lt a) = Lt (numsubst0 t a)" - "subst0 t (Le a) = Le (numsubst0 t a)" - "subst0 t (Gt a) = Gt (numsubst0 t a)" - "subst0 t (Ge a) = Ge (numsubst0 t a)" - "subst0 t (Eq a) = Eq (numsubst0 t a)" - "subst0 t (NEq a) = NEq (numsubst0 t a)" - "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)" - "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)" - "subst0 t (NOT p) = NOT (subst0 t p)" - "subst0 t (And p q) = And (subst0 t p) (subst0 t q)" - "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)" - "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)" - "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)" - "subst0 t (Closed P) = (Closed P)" - "subst0 t (NClosed P) = (NClosed P)" - -lemma subst0_I: assumes qfp: "qfree p" - shows "Ifm bbs (b#bs) (subst0 a p) = Ifm bbs ((Inum (b#bs) a)#bs) p" - using qfp numsubst0_I[where b="b" and bs="bs" and a="a"] - by (induct p) (simp_all add: gr0_conv_Suc) - - -consts - decrnum:: "num \ num" - decr :: "fm \ fm" - -recdef decrnum "measure size" - "decrnum (Bound n) = Bound (n - 1)" - "decrnum (Neg a) = Neg (decrnum a)" - "decrnum (Add a b) = Add (decrnum a) (decrnum b)" - "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" - "decrnum (Mul c a) = Mul c (decrnum a)" - "decrnum (CN n i a) = (CN (n - 1) i (decrnum a))" - "decrnum a = a" - -recdef decr "measure size" - "decr (Lt a) = Lt (decrnum a)" - "decr (Le a) = Le (decrnum a)" - "decr (Gt a) = Gt (decrnum a)" - "decr (Ge a) = Ge (decrnum a)" - "decr (Eq a) = Eq (decrnum a)" - "decr (NEq a) = NEq (decrnum a)" - "decr (Dvd i a) = Dvd i (decrnum a)" - "decr (NDvd i a) = NDvd i (decrnum a)" - "decr (NOT p) = NOT (decr p)" - "decr (And p q) = And (decr p) (decr q)" - "decr (Or p q) = Or (decr p) (decr q)" - "decr (Imp p q) = Imp (decr p) (decr q)" - "decr (Iff p q) = Iff (decr p) (decr q)" - "decr p = p" - -lemma decrnum: assumes nb: "numbound0 t" - shows "Inum (x#bs) t = Inum bs (decrnum t)" - using nb by (induct t rule: decrnum.induct, auto simp add: gr0_conv_Suc) - -lemma decr: assumes nb: "bound0 p" - shows "Ifm bbs (x#bs) p = Ifm bbs bs (decr p)" - using nb - by (induct p rule: decr.induct, simp_all add: gr0_conv_Suc decrnum) - -lemma decr_qf: "bound0 p \ qfree (decr p)" -by (induct p, simp_all) - -consts - isatom :: "fm \ bool" (* test for atomicity *) -recdef isatom "measure size" - "isatom T = True" - "isatom F = True" - "isatom (Lt a) = True" - "isatom (Le a) = True" - "isatom (Gt a) = True" - "isatom (Ge a) = True" - "isatom (Eq a) = True" - "isatom (NEq a) = True" - "isatom (Dvd i b) = True" - "isatom (NDvd i b) = True" - "isatom (Closed P) = True" - "isatom (NClosed P) = True" - "isatom p = False" - -lemma numsubst0_numbound0: assumes nb: "numbound0 t" - shows "numbound0 (numsubst0 t a)" -using nb apply (induct a rule: numbound0.induct) -apply simp_all -apply (case_tac n, simp_all) -done - -lemma subst0_bound0: assumes qf: "qfree p" and nb: "numbound0 t" - shows "bound0 (subst0 t p)" -using qf numsubst0_numbound0[OF nb] by (induct p rule: subst0.induct, auto) - -lemma bound0_qf: "bound0 p \ qfree p" -by (induct p, simp_all) - - -constdefs djf:: "('a \ fm) \ 'a \ fm \ fm" - "djf f p q \ (if q=T then T else if q=F then f p else - (let fp = f p in case fp of T \ T | F \ q | _ \ Or (f p) q))" -constdefs evaldjf:: "('a \ fm) \ 'a list \ fm" - "evaldjf f ps \ foldr (djf f) ps F" - -lemma djf_Or: "Ifm bbs bs (djf f p q) = Ifm bbs bs (Or (f p) q)" -by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) -(cases "f p", simp_all add: Let_def djf_def) - -lemma evaldjf_ex: "Ifm bbs bs (evaldjf f ps) = (\ p \ set ps. Ifm bbs bs (f p))" - by(induct ps, simp_all add: evaldjf_def djf_Or) - -lemma evaldjf_bound0: - assumes nb: "\ x\ set xs. bound0 (f x)" - shows "bound0 (evaldjf f xs)" - using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) - -lemma evaldjf_qf: - assumes nb: "\ x\ set xs. qfree (f x)" - shows "qfree (evaldjf f xs)" - using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) - -consts disjuncts :: "fm \ fm list" -recdef disjuncts "measure size" - "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)" - "disjuncts F = []" - "disjuncts p = [p]" - -lemma disjuncts: "(\ q\ set (disjuncts p). Ifm bbs bs q) = Ifm bbs bs p" -by(induct p rule: disjuncts.induct, auto) - -lemma disjuncts_nb: "bound0 p \ \ q\ set (disjuncts p). bound0 q" -proof- - assume nb: "bound0 p" - hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto) - thus ?thesis by (simp only: list_all_iff) -qed - -lemma disjuncts_qf: "qfree p \ \ q\ set (disjuncts p). qfree q" -proof- - assume qf: "qfree p" - hence "list_all qfree (disjuncts p)" - by (induct p rule: disjuncts.induct, auto) - thus ?thesis by (simp only: list_all_iff) -qed - -constdefs DJ :: "(fm \ fm) \ fm \ fm" - "DJ f p \ evaldjf f (disjuncts p)" - -lemma DJ: assumes fdj: "\ p q. f (Or p q) = Or (f p) (f q)" - and fF: "f F = F" - shows "Ifm bbs bs (DJ f p) = Ifm bbs bs (f p)" -proof- - have "Ifm bbs bs (DJ f p) = (\ q \ set (disjuncts p). Ifm bbs bs (f q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = Ifm bbs bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto) - finally show ?thesis . -qed - -lemma DJ_qf: assumes - fqf: "\ p. qfree p \ qfree (f p)" - shows "\p. qfree p \ qfree (DJ f p) " -proof(clarify) - fix p assume qf: "qfree p" - have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def) - from disjuncts_qf[OF qf] have "\ q\ set (disjuncts p). qfree q" . - with fqf have th':"\ q\ set (disjuncts p). qfree (f q)" by blast - - from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp -qed - -lemma DJ_qe: assumes qe: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bbs bs (qe p) = Ifm bbs bs (E p))" - shows "\ bs p. qfree p \ qfree (DJ qe p) \ (Ifm bbs bs ((DJ qe p)) = Ifm bbs bs (E p))" -proof(clarify) - fix p::fm and bs - assume qf: "qfree p" - from qe have qth: "\ p. qfree p \ qfree (qe p)" by blast - from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto - have "Ifm bbs bs (DJ qe p) = (\ q\ set (disjuncts p). Ifm bbs bs (qe q))" - by (simp add: DJ_def evaldjf_ex) - also have "\ = (\ q \ set(disjuncts p). Ifm bbs bs (E q))" using qe disjuncts_qf[OF qf] by auto - also have "\ = Ifm bbs bs (E p)" by (induct p rule: disjuncts.induct, auto) - finally show "qfree (DJ qe p) \ Ifm bbs bs (DJ qe p) = Ifm bbs bs (E p)" using qfth by blast -qed - (* Simplification *) - - (* Algebraic simplifications for nums *) -consts bnds:: "num \ nat list" - lex_ns:: "nat list \ nat list \ bool" -recdef bnds "measure size" - "bnds (Bound n) = [n]" - "bnds (CN n c a) = n#(bnds a)" - "bnds (Neg a) = bnds a" - "bnds (Add a b) = (bnds a)@(bnds b)" - "bnds (Sub a b) = (bnds a)@(bnds b)" - "bnds (Mul i a) = bnds a" - "bnds a = []" -recdef lex_ns "measure (\ (xs,ys). length xs + length ys)" - "lex_ns ([], ms) = True" - "lex_ns (ns, []) = False" - "lex_ns (n#ns, m#ms) = (n ((n = m) \ lex_ns (ns,ms))) " -constdefs lex_bnd :: "num \ num \ bool" - "lex_bnd t s \ lex_ns (bnds t, bnds s)" - -consts - numadd:: "num \ num \ num" -recdef numadd "measure (\ (t,s). num_size t + num_size s)" - "numadd (CN n1 c1 r1 ,CN n2 c2 r2) = - (if n1=n2 then - (let c = c1 + c2 - in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2)))) - else if n1 \ n2 then CN n1 c1 (numadd (r1,Add (Mul c2 (Bound n2)) r2)) - else CN n2 c2 (numadd (Add (Mul c1 (Bound n1)) r1,r2)))" - "numadd (CN n1 c1 r1, t) = CN n1 c1 (numadd (r1, t))" - "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" - "numadd (C b1, C b2) = C (b1+b2)" - "numadd (a,b) = Add a b" - -(*function (sequential) - numadd :: "num \ num \ num" -where - "numadd (Add (Mul c1 (Bound n1)) r1) (Add (Mul c2 (Bound n2)) r2) = - (if n1 = n2 then (let c = c1 + c2 - in (if c = 0 then numadd r1 r2 else - Add (Mul c (Bound n1)) (numadd r1 r2))) - else if n1 \ n2 then - Add (Mul c1 (Bound n1)) (numadd r1 (Add (Mul c2 (Bound n2)) r2)) - else - Add (Mul c2 (Bound n2)) (numadd (Add (Mul c1 (Bound n1)) r1) r2))" - | "numadd (Add (Mul c1 (Bound n1)) r1) t = - Add (Mul c1 (Bound n1)) (numadd r1 t)" - | "numadd t (Add (Mul c2 (Bound n2)) r2) = - Add (Mul c2 (Bound n2)) (numadd t r2)" - | "numadd (C b1) (C b2) = C (b1 + b2)" - | "numadd a b = Add a b" -apply pat_completeness apply auto*) - -lemma numadd: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" -apply (induct t s rule: numadd.induct, simp_all add: Let_def) -apply (case_tac "c1+c2 = 0",case_tac "n1 \ n2", simp_all) - apply (case_tac "n1 = n2") - apply(simp_all add: algebra_simps) -apply(simp add: left_distrib[symmetric]) -done - -lemma numadd_nb: "\ numbound0 t ; numbound0 s\ \ numbound0 (numadd (t,s))" -by (induct t s rule: numadd.induct, auto simp add: Let_def) - -fun - nummul :: "int \ num \ num" -where - "nummul i (C j) = C (i * j)" - | "nummul i (CN n c t) = CN n (c*i) (nummul i t)" - | "nummul i t = Mul i t" - -lemma nummul: "\ i. Inum bs (nummul i t) = Inum bs (Mul i t)" -by (induct t rule: nummul.induct, auto simp add: algebra_simps numadd) - -lemma nummul_nb: "\ i. numbound0 t \ numbound0 (nummul i t)" -by (induct t rule: nummul.induct, auto simp add: numadd_nb) - -constdefs numneg :: "num \ num" - "numneg t \ nummul (- 1) t" - -constdefs numsub :: "num \ num \ num" - "numsub s t \ (if s = t then C 0 else numadd (s, numneg t))" - -lemma numneg: "Inum bs (numneg t) = Inum bs (Neg t)" -using numneg_def nummul by simp - -lemma numneg_nb: "numbound0 t \ numbound0 (numneg t)" -using numneg_def nummul_nb by simp - -lemma numsub: "Inum bs (numsub a b) = Inum bs (Sub a b)" -using numneg numadd numsub_def by simp - -lemma numsub_nb: "\ numbound0 t ; numbound0 s\ \ numbound0 (numsub t s)" -using numsub_def numadd_nb numneg_nb by simp - -fun - simpnum :: "num \ num" -where - "simpnum (C j) = C j" - | "simpnum (Bound n) = CN n 1 (C 0)" - | "simpnum (Neg t) = numneg (simpnum t)" - | "simpnum (Add t s) = numadd (simpnum t, simpnum s)" - | "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" - | "simpnum (Mul i t) = (if i = 0 then C 0 else nummul i (simpnum t))" - | "simpnum t = t" - -lemma simpnum_ci: "Inum bs (simpnum t) = Inum bs t" -by (induct t rule: simpnum.induct, auto simp add: numneg numadd numsub nummul) - -lemma simpnum_numbound0: - "numbound0 t \ numbound0 (simpnum t)" -by (induct t rule: simpnum.induct, auto simp add: numadd_nb numsub_nb nummul_nb numneg_nb) - -fun - not :: "fm \ fm" -where - "not (NOT p) = p" - | "not T = F" - | "not F = T" - | "not p = NOT p" -lemma not: "Ifm bbs bs (not p) = Ifm bbs bs (NOT p)" -by (cases p) auto -lemma not_qf: "qfree p \ qfree (not p)" -by (cases p, auto) -lemma not_bn: "bound0 p \ bound0 (not p)" -by (cases p, auto) - -constdefs conj :: "fm \ fm \ fm" - "conj p q \ (if (p = F \ q=F) then F else if p=T then q else if q=T then p else And p q)" -lemma conj: "Ifm bbs bs (conj p q) = Ifm bbs bs (And p q)" -by (cases "p=F \ q=F",simp_all add: conj_def) (cases p,simp_all) - -lemma conj_qf: "\qfree p ; qfree q\ \ qfree (conj p q)" -using conj_def by auto -lemma conj_nb: "\bound0 p ; bound0 q\ \ bound0 (conj p q)" -using conj_def by auto - -constdefs disj :: "fm \ fm \ fm" - "disj p q \ (if (p = T \ q=T) then T else if p=F then q else if q=F then p else Or p q)" - -lemma disj: "Ifm bbs bs (disj p q) = Ifm bbs bs (Or p q)" -by (cases "p=T \ q=T",simp_all add: disj_def) (cases p,simp_all) -lemma disj_qf: "\qfree p ; qfree q\ \ qfree (disj p q)" -using disj_def by auto -lemma disj_nb: "\bound0 p ; bound0 q\ \ bound0 (disj p q)" -using disj_def by auto - -constdefs imp :: "fm \ fm \ fm" - "imp p q \ (if (p = F \ q=T) then T else if p=T then q else if q=F then not p else Imp p q)" -lemma imp: "Ifm bbs bs (imp p q) = Ifm bbs bs (Imp p q)" -by (cases "p=F \ q=T",simp_all add: imp_def,cases p) (simp_all add: not) -lemma imp_qf: "\qfree p ; qfree q\ \ qfree (imp p q)" -using imp_def by (cases "p=F \ q=T",simp_all add: imp_def,cases p) (simp_all add: not_qf) -lemma imp_nb: "\bound0 p ; bound0 q\ \ bound0 (imp p q)" -using imp_def by (cases "p=F \ q=T",simp_all add: imp_def,cases p) simp_all - -constdefs iff :: "fm \ fm \ fm" - "iff p q \ (if (p = q) then T else if (p = not q \ not p = q) then F else - if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else - Iff p q)" -lemma iff: "Ifm bbs bs (iff p q) = Ifm bbs bs (Iff p q)" - by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp add:not) -(cases "not p= q", auto simp add:not) -lemma iff_qf: "\qfree p ; qfree q\ \ qfree (iff p q)" - by (unfold iff_def,cases "p=q", auto simp add: not_qf) -lemma iff_nb: "\bound0 p ; bound0 q\ \ bound0 (iff p q)" -using iff_def by (unfold iff_def,cases "p=q", auto simp add: not_bn) - -function (sequential) - simpfm :: "fm \ fm" -where - "simpfm (And p q) = conj (simpfm p) (simpfm q)" - | "simpfm (Or p q) = disj (simpfm p) (simpfm q)" - | "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" - | "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" - | "simpfm (NOT p) = not (simpfm p)" - | "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \ if (v < 0) then T else F - | _ \ Lt a')" - | "simpfm (Le a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Le a')" - | "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \ if (v > 0) then T else F | _ \ Gt a')" - | "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ Ge a')" - | "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \ if (v = 0) then T else F | _ \ Eq a')" - | "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \ if (v \ 0) then T else F | _ \ NEq a')" - | "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a) - else if (abs i = 1) then T - else let a' = simpnum a in case a' of C v \ if (i dvd v) then T else F | _ \ Dvd i a')" - | "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a) - else if (abs i = 1) then F - else let a' = simpnum a in case a' of C v \ if (\(i dvd v)) then T else F | _ \ NDvd i a')" - | "simpfm p = p" -by pat_completeness auto -termination by (relation "measure fmsize") auto - -lemma simpfm: "Ifm bbs bs (simpfm p) = Ifm bbs bs p" -proof(induct p rule: simpfm.induct) - case (6 a) let ?sa = "simpnum a" from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (7 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (8 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (9 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (10 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (11 a) let ?sa = "simpnum a" - from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp - {fix v assume "?sa = C v" hence ?case using sa by simp } - moreover {assume "\ (\ v. ?sa = C v)" hence ?case using sa - by (cases ?sa, simp_all add: Let_def)} - ultimately show ?case by blast -next - case (12 i a) let ?sa = "simpnum a" from simpnum_ci - have sa: "Inum bs ?sa = Inum bs a" by simp - have "i=0 \ abs i = 1 \ (i\0 \ (abs i \ 1))" by auto - {assume "i=0" hence ?case using "12.hyps" by (simp add: dvd_def Let_def)} - moreover - {assume i1: "abs i = 1" - from zdvd_1_left[where m = "Inum bs a"] uminus_dvd_conv[where d="1" and t="Inum bs a"] - have ?case using i1 apply (cases "i=0", simp_all add: Let_def) - by (cases "i > 0", simp_all)} - moreover - {assume inz: "i\0" and cond: "abs i \ 1" - {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond - by (cases "abs i = 1", auto) } - moreover {assume "\ (\ v. ?sa = C v)" - hence "simpfm (Dvd i a) = Dvd i ?sa" using inz cond - by (cases ?sa, auto simp add: Let_def) - hence ?case using sa by simp} - ultimately have ?case by blast} - ultimately show ?case by blast -next - case (13 i a) let ?sa = "simpnum a" from simpnum_ci - have sa: "Inum bs ?sa = Inum bs a" by simp - have "i=0 \ abs i = 1 \ (i\0 \ (abs i \ 1))" by auto - {assume "i=0" hence ?case using "13.hyps" by (simp add: dvd_def Let_def)} - moreover - {assume i1: "abs i = 1" - from zdvd_1_left[where m = "Inum bs a"] uminus_dvd_conv[where d="1" and t="Inum bs a"] - have ?case using i1 apply (cases "i=0", simp_all add: Let_def) - apply (cases "i > 0", simp_all) done} - moreover - {assume inz: "i\0" and cond: "abs i \ 1" - {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond - by (cases "abs i = 1", auto) } - moreover {assume "\ (\ v. ?sa = C v)" - hence "simpfm (NDvd i a) = NDvd i ?sa" using inz cond - by (cases ?sa, auto simp add: Let_def) - hence ?case using sa by simp} - ultimately have ?case by blast} - ultimately show ?case by blast -qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not) - -lemma simpfm_bound0: "bound0 p \ bound0 (simpfm p)" -proof(induct p rule: simpfm.induct) - case (6 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (7 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (8 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (9 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (10 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (11 a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (12 i a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -next - case (13 i a) hence nb: "numbound0 a" by simp - hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) - thus ?case by (cases "simpnum a", auto simp add: Let_def) -qed(auto simp add: disj_def imp_def iff_def conj_def not_bn) - -lemma simpfm_qf: "qfree p \ qfree (simpfm p)" -by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def) - (case_tac "simpnum a",auto)+ - - (* Generic quantifier elimination *) -consts qelim :: "fm \ (fm \ fm) \ fm" -recdef qelim "measure fmsize" - "qelim (E p) = (\ qe. DJ qe (qelim p qe))" - "qelim (A p) = (\ qe. not (qe ((qelim (NOT p) qe))))" - "qelim (NOT p) = (\ qe. not (qelim p qe))" - "qelim (And p q) = (\ qe. conj (qelim p qe) (qelim q qe))" - "qelim (Or p q) = (\ qe. disj (qelim p qe) (qelim q qe))" - "qelim (Imp p q) = (\ qe. imp (qelim p qe) (qelim q qe))" - "qelim (Iff p q) = (\ qe. iff (qelim p qe) (qelim q qe))" - "qelim p = (\ y. simpfm p)" - -(*function (sequential) - qelim :: "(fm \ fm) \ fm \ fm" -where - "qelim qe (E p) = DJ qe (qelim qe p)" - | "qelim qe (A p) = not (qe ((qelim qe (NOT p))))" - | "qelim qe (NOT p) = not (qelim qe p)" - | "qelim qe (And p q) = conj (qelim qe p) (qelim qe q)" - | "qelim qe (Or p q) = disj (qelim qe p) (qelim qe q)" - | "qelim qe (Imp p q) = imp (qelim qe p) (qelim qe q)" - | "qelim qe (Iff p q) = iff (qelim qe p) (qelim qe q)" - | "qelim qe p = simpfm p" -by pat_completeness auto -termination by (relation "measure (fmsize o snd)") auto*) - -lemma qelim_ci: - assumes qe_inv: "\ bs p. qfree p \ qfree (qe p) \ (Ifm bbs bs (qe p) = Ifm bbs bs (E p))" - shows "\ bs. qfree (qelim p qe) \ (Ifm bbs bs (qelim p qe) = Ifm bbs bs p)" -using qe_inv DJ_qe[OF qe_inv] -by(induct p rule: qelim.induct) -(auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf - simpfm simpfm_qf simp del: simpfm.simps) - (* Linearity for fm where Bound 0 ranges over \ *) - -fun - zsplit0 :: "num \ int \ num" (* splits the bounded from the unbounded part*) -where - "zsplit0 (C c) = (0,C c)" - | "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))" - | "zsplit0 (CN n i a) = - (let (i',a') = zsplit0 a - in if n=0 then (i+i', a') else (i',CN n i a'))" - | "zsplit0 (Neg a) = (let (i',a') = zsplit0 a in (-i', Neg a'))" - | "zsplit0 (Add a b) = (let (ia,a') = zsplit0 a ; - (ib,b') = zsplit0 b - in (ia+ib, Add a' b'))" - | "zsplit0 (Sub a b) = (let (ia,a') = zsplit0 a ; - (ib,b') = zsplit0 b - in (ia-ib, Sub a' b'))" - | "zsplit0 (Mul i a) = (let (i',a') = zsplit0 a in (i*i', Mul i a'))" - -lemma zsplit0_I: - shows "\ n a. zsplit0 t = (n,a) \ (Inum ((x::int) #bs) (CN 0 n a) = Inum (x #bs) t) \ numbound0 a" - (is "\ n a. ?S t = (n,a) \ (?I x (CN 0 n a) = ?I x t) \ ?N a") -proof(induct t rule: zsplit0.induct) - case (1 c n a) thus ?case by auto -next - case (2 m n a) thus ?case by (cases "m=0") auto -next - case (3 m i a n a') - let ?j = "fst (zsplit0 a)" - let ?b = "snd (zsplit0 a)" - have abj: "zsplit0 a = (?j,?b)" by simp - {assume "m\0" - with prems(1)[OF abj] prems(2) have ?case by (auto simp add: Let_def split_def)} - moreover - {assume m0: "m =0" - from abj have th: "a'=?b \ n=i+?j" using prems - by (simp add: Let_def split_def) - from abj prems have th2: "(?I x (CN 0 ?j ?b) = ?I x a) \ ?N ?b" by blast - from th have "?I x (CN 0 n a') = ?I x (CN 0 (i+?j) ?b)" by simp - also from th2 have "\ = ?I x (CN 0 i (CN 0 ?j ?b))" by (simp add: left_distrib) - finally have "?I x (CN 0 n a') = ?I x (CN 0 i a)" using th2 by simp - with th2 th have ?case using m0 by blast} -ultimately show ?case by blast -next - case (4 t n a) - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \ n=-?nt" using prems - by (simp add: Let_def split_def) - from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - from th2[simplified] th[simplified] show ?case by simp -next - case (5 s t n a) - let ?ns = "fst (zsplit0 s)" - let ?as = "snd (zsplit0 s)" - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abjs: "zsplit0 s = (?ns,?as)" by simp - moreover have abjt: "zsplit0 t = (?nt,?at)" by simp - ultimately have th: "a=Add ?as ?at \ n=?ns + ?nt" using prems - by (simp add: Let_def split_def) - from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast - from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \ numbound0 xb)" by auto - with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast - from th3[simplified] th2[simplified] th[simplified] show ?case - by (simp add: left_distrib) -next - case (6 s t n a) - let ?ns = "fst (zsplit0 s)" - let ?as = "snd (zsplit0 s)" - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abjs: "zsplit0 s = (?ns,?as)" by simp - moreover have abjt: "zsplit0 t = (?nt,?at)" by simp - ultimately have th: "a=Sub ?as ?at \ n=?ns - ?nt" using prems - by (simp add: Let_def split_def) - from abjs[symmetric] have bluddy: "\ x y. (x,y) = zsplit0 s" by blast - from prems have "(\ x y. (x,y) = zsplit0 s) \ (\xa xb. zsplit0 t = (xa, xb) \ Inum (x # bs) (CN 0 xa xb) = Inum (x # bs) t \ numbound0 xb)" by auto - with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - from abjs prems have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \ ?N ?as" by blast - from th3[simplified] th2[simplified] th[simplified] show ?case - by (simp add: left_diff_distrib) -next - case (7 i t n a) - let ?nt = "fst (zsplit0 t)" - let ?at = "snd (zsplit0 t)" - have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \ n=i*?nt" using prems - by (simp add: Let_def split_def) - from abj prems have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \ ?N ?at" by blast - hence " ?I x (Mul i t) = i * ?I x (CN 0 ?nt ?at)" by simp - also have "\ = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: right_distrib) - finally show ?case using th th2 by simp -qed - -consts - iszlfm :: "fm \ bool" (* Linearity test for fm *) -recdef iszlfm "measure size" - "iszlfm (And p q) = (iszlfm p \ iszlfm q)" - "iszlfm (Or p q) = (iszlfm p \ iszlfm q)" - "iszlfm (Eq (CN 0 c e)) = (c>0 \ numbound0 e)" - "iszlfm (NEq (CN 0 c e)) = (c>0 \ numbound0 e)" - "iszlfm (Lt (CN 0 c e)) = (c>0 \ numbound0 e)" - "iszlfm (Le (CN 0 c e)) = (c>0 \ numbound0 e)" - "iszlfm (Gt (CN 0 c e)) = (c>0 \ numbound0 e)" - "iszlfm (Ge (CN 0 c e)) = ( c>0 \ numbound0 e)" - "iszlfm (Dvd i (CN 0 c e)) = - (c>0 \ i>0 \ numbound0 e)" - "iszlfm (NDvd i (CN 0 c e))= - (c>0 \ i>0 \ numbound0 e)" - "iszlfm p = (isatom p \ (bound0 p))" - -lemma zlin_qfree: "iszlfm p \ qfree p" - by (induct p rule: iszlfm.induct) auto - -consts - zlfm :: "fm \ fm" (* Linearity transformation for fm *) -recdef zlfm "measure fmsize" - "zlfm (And p q) = And (zlfm p) (zlfm q)" - "zlfm (Or p q) = Or (zlfm p) (zlfm q)" - "zlfm (Imp p q) = Or (zlfm (NOT p)) (zlfm q)" - "zlfm (Iff p q) = Or (And (zlfm p) (zlfm q)) (And (zlfm (NOT p)) (zlfm (NOT q)))" - "zlfm (Lt a) = (let (c,r) = zsplit0 a in - if c=0 then Lt r else - if c>0 then (Lt (CN 0 c r)) else (Gt (CN 0 (- c) (Neg r))))" - "zlfm (Le a) = (let (c,r) = zsplit0 a in - if c=0 then Le r else - if c>0 then (Le (CN 0 c r)) else (Ge (CN 0 (- c) (Neg r))))" - "zlfm (Gt a) = (let (c,r) = zsplit0 a in - if c=0 then Gt r else - if c>0 then (Gt (CN 0 c r)) else (Lt (CN 0 (- c) (Neg r))))" - "zlfm (Ge a) = (let (c,r) = zsplit0 a in - if c=0 then Ge r else - if c>0 then (Ge (CN 0 c r)) else (Le (CN 0 (- c) (Neg r))))" - "zlfm (Eq a) = (let (c,r) = zsplit0 a in - if c=0 then Eq r else - if c>0 then (Eq (CN 0 c r)) else (Eq (CN 0 (- c) (Neg r))))" - "zlfm (NEq a) = (let (c,r) = zsplit0 a in - if c=0 then NEq r else - if c>0 then (NEq (CN 0 c r)) else (NEq (CN 0 (- c) (Neg r))))" - "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a) - else (let (c,r) = zsplit0 a in - if c=0 then (Dvd (abs i) r) else - if c>0 then (Dvd (abs i) (CN 0 c r)) - else (Dvd (abs i) (CN 0 (- c) (Neg r)))))" - "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a) - else (let (c,r) = zsplit0 a in - if c=0 then (NDvd (abs i) r) else - if c>0 then (NDvd (abs i) (CN 0 c r)) - else (NDvd (abs i) (CN 0 (- c) (Neg r)))))" - "zlfm (NOT (And p q)) = Or (zlfm (NOT p)) (zlfm (NOT q))" - "zlfm (NOT (Or p q)) = And (zlfm (NOT p)) (zlfm (NOT q))" - "zlfm (NOT (Imp p q)) = And (zlfm p) (zlfm (NOT q))" - "zlfm (NOT (Iff p q)) = Or (And(zlfm p) (zlfm(NOT q))) (And (zlfm(NOT p)) (zlfm q))" - "zlfm (NOT (NOT p)) = zlfm p" - "zlfm (NOT T) = F" - "zlfm (NOT F) = T" - "zlfm (NOT (Lt a)) = zlfm (Ge a)" - "zlfm (NOT (Le a)) = zlfm (Gt a)" - "zlfm (NOT (Gt a)) = zlfm (Le a)" - "zlfm (NOT (Ge a)) = zlfm (Lt a)" - "zlfm (NOT (Eq a)) = zlfm (NEq a)" - "zlfm (NOT (NEq a)) = zlfm (Eq a)" - "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)" - "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)" - "zlfm (NOT (Closed P)) = NClosed P" - "zlfm (NOT (NClosed P)) = Closed P" - "zlfm p = p" (hints simp add: fmsize_pos) - -lemma zlfm_I: - assumes qfp: "qfree p" - shows "(Ifm bbs (i#bs) (zlfm p) = Ifm bbs (i# bs) p) \ iszlfm (zlfm p)" - (is "(?I (?l p) = ?I p) \ ?L (?l p)") -using qfp -proof(induct p rule: zlfm.induct) - case (5 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - from prems Ia nb show ?case - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done -next - case (6 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - from prems Ia nb show ?case - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done -next - case (7 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - from prems Ia nb show ?case - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done -next - case (8 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - from prems Ia nb show ?case - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done -next - case (9 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - from prems Ia nb show ?case - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done -next - case (10 a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - from prems Ia nb show ?case - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done -next - case (11 j a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0) \ (j\ 0 \ ?c<0)" by arith - moreover - {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def) - hence ?case using prems by (simp del: zlfm.simps add: zdvd_0_left)} - moreover - {assume "?c=0" and "j\0" hence ?case - using zsplit0_I[OF spl, where x="i" and bs="bs"] - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done} - moreover - {assume cp: "?c > 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" - by (simp add: nb Let_def split_def) - hence ?case using Ia cp jnz by (simp add: Let_def split_def)} - moreover - {assume cn: "?c < 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" - by (simp add: nb Let_def split_def) - hence ?case using Ia cn jnz zdvd_zminus_iff[where m="abs j" and n="?c*i + ?N ?r" ] - by (simp add: Let_def split_def) } - ultimately show ?case by blast -next - case (12 j a) - let ?c = "fst (zsplit0 a)" - let ?r = "snd (zsplit0 a)" - have spl: "zsplit0 a = (?c,?r)" by simp - from zsplit0_I[OF spl, where x="i" and bs="bs"] - have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto - let ?N = "\ t. Inum (i#bs) t" - have "j=0 \ (j\0 \ ?c = 0) \ (j\0 \ ?c >0) \ (j\ 0 \ ?c<0)" by arith - moreover - {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def) - hence ?case using prems by (simp del: zlfm.simps add: zdvd_0_left)} - moreover - {assume "?c=0" and "j\0" hence ?case - using zsplit0_I[OF spl, where x="i" and bs="bs"] - apply (auto simp add: Let_def split_def algebra_simps) - apply (cases "?r",auto) - apply (case_tac nat, auto) - done} - moreover - {assume cp: "?c > 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" - by (simp add: nb Let_def split_def) - hence ?case using Ia cp jnz by (simp add: Let_def split_def) } - moreover - {assume cn: "?c < 0" and jnz: "j\0" hence l: "?L (?l (Dvd j a))" - by (simp add: nb Let_def split_def) - hence ?case using Ia cn jnz zdvd_zminus_iff[where m="abs j" and n="?c*i + ?N ?r" ] - by (simp add: Let_def split_def)} - ultimately show ?case by blast -qed auto - -consts - plusinf:: "fm \ fm" (* Virtual substitution of +\*) - minusinf:: "fm \ fm" (* Virtual substitution of -\*) - \ :: "fm \ int" (* Compute lcm {d| N\<^isup>?\<^isup> Dvd c*x+t \ p}*) - d\ :: "fm \ int \ bool" (* checks if a given l divides all the ds above*) - -recdef minusinf "measure size" - "minusinf (And p q) = And (minusinf p) (minusinf q)" - "minusinf (Or p q) = Or (minusinf p) (minusinf q)" - "minusinf (Eq (CN 0 c e)) = F" - "minusinf (NEq (CN 0 c e)) = T" - "minusinf (Lt (CN 0 c e)) = T" - "minusinf (Le (CN 0 c e)) = T" - "minusinf (Gt (CN 0 c e)) = F" - "minusinf (Ge (CN 0 c e)) = F" - "minusinf p = p" - -lemma minusinf_qfree: "qfree p \ qfree (minusinf p)" - by (induct p rule: minusinf.induct, auto) - -recdef plusinf "measure size" - "plusinf (And p q) = And (plusinf p) (plusinf q)" - "plusinf (Or p q) = Or (plusinf p) (plusinf q)" - "plusinf (Eq (CN 0 c e)) = F" - "plusinf (NEq (CN 0 c e)) = T" - "plusinf (Lt (CN 0 c e)) = F" - "plusinf (Le (CN 0 c e)) = F" - "plusinf (Gt (CN 0 c e)) = T" - "plusinf (Ge (CN 0 c e)) = T" - "plusinf p = p" - -recdef \ "measure size" - "\ (And p q) = zlcm (\ p) (\ q)" - "\ (Or p q) = zlcm (\ p) (\ q)" - "\ (Dvd i (CN 0 c e)) = i" - "\ (NDvd i (CN 0 c e)) = i" - "\ p = 1" - -recdef d\ "measure size" - "d\ (And p q) = (\ d. d\ p d \ d\ q d)" - "d\ (Or p q) = (\ d. d\ p d \ d\ q d)" - "d\ (Dvd i (CN 0 c e)) = (\ d. i dvd d)" - "d\ (NDvd i (CN 0 c e)) = (\ d. i dvd d)" - "d\ p = (\ d. True)" - -lemma delta_mono: - assumes lin: "iszlfm p" - and d: "d dvd d'" - and ad: "d\ p d" - shows "d\ p d'" - using lin ad d -proof(induct p rule: iszlfm.induct) - case (9 i c e) thus ?case using d - by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) -next - case (10 i c e) thus ?case using d - by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"]) -qed simp_all - -lemma \ : assumes lin:"iszlfm p" - shows "d\ p (\ p) \ \ p >0" -using lin -proof (induct p rule: iszlfm.induct) - case (1 p q) - let ?d = "\ (And p q)" - from prems zlcm_pos have dp: "?d >0" by simp - have d1: "\ p dvd \ (And p q)" using prems by simp - hence th: "d\ p ?d" using delta_mono prems(3-4) by(simp del:dvd_zlcm_self1) - have "\ q dvd \ (And p q)" using prems by simp - hence th': "d\ q ?d" using delta_mono prems by(simp del:dvd_zlcm_self2) - from th th' dp show ?case by simp -next - case (2 p q) - let ?d = "\ (And p q)" - from prems zlcm_pos have dp: "?d >0" by simp - have "\ p dvd \ (And p q)" using prems by simp - hence th: "d\ p ?d" using delta_mono prems by(simp del:dvd_zlcm_self1) - have "\ q dvd \ (And p q)" using prems by simp - hence th': "d\ q ?d" using delta_mono prems by(simp del:dvd_zlcm_self2) - from th th' dp show ?case by simp -qed simp_all - - -consts - a\ :: "fm \ int \ fm" (* adjusts the coeffitients of a formula *) - d\ :: "fm \ int \ bool" (* tests if all coeffs c of c divide a given l*) - \ :: "fm \ int" (* computes the lcm of all coefficients of x*) - \ :: "fm \ num list" - \ :: "fm \ num list" - -recdef a\ "measure size" - "a\ (And p q) = (\ k. And (a\ p k) (a\ q k))" - "a\ (Or p q) = (\ k. Or (a\ p k) (a\ q k))" - "a\ (Eq (CN 0 c e)) = (\ k. Eq (CN 0 1 (Mul (k div c) e)))" - "a\ (NEq (CN 0 c e)) = (\ k. NEq (CN 0 1 (Mul (k div c) e)))" - "a\ (Lt (CN 0 c e)) = (\ k. Lt (CN 0 1 (Mul (k div c) e)))" - "a\ (Le (CN 0 c e)) = (\ k. Le (CN 0 1 (Mul (k div c) e)))" - "a\ (Gt (CN 0 c e)) = (\ k. Gt (CN 0 1 (Mul (k div c) e)))" - "a\ (Ge (CN 0 c e)) = (\ k. Ge (CN 0 1 (Mul (k div c) e)))" - "a\ (Dvd i (CN 0 c e)) =(\ k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" - "a\ (NDvd i (CN 0 c e))=(\ k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))" - "a\ p = (\ k. p)" - -recdef d\ "measure size" - "d\ (And p q) = (\ k. (d\ p k) \ (d\ q k))" - "d\ (Or p q) = (\ k. (d\ p k) \ (d\ q k))" - "d\ (Eq (CN 0 c e)) = (\ k. c dvd k)" - "d\ (NEq (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Lt (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Le (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Gt (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Ge (CN 0 c e)) = (\ k. c dvd k)" - "d\ (Dvd i (CN 0 c e)) =(\ k. c dvd k)" - "d\ (NDvd i (CN 0 c e))=(\ k. c dvd k)" - "d\ p = (\ k. True)" - -recdef \ "measure size" - "\ (And p q) = zlcm (\ p) (\ q)" - "\ (Or p q) = zlcm (\ p) (\ q)" - "\ (Eq (CN 0 c e)) = c" - "\ (NEq (CN 0 c e)) = c" - "\ (Lt (CN 0 c e)) = c" - "\ (Le (CN 0 c e)) = c" - "\ (Gt (CN 0 c e)) = c" - "\ (Ge (CN 0 c e)) = c" - "\ (Dvd i (CN 0 c e)) = c" - "\ (NDvd i (CN 0 c e))= c" - "\ p = 1" - -recdef \ "measure size" - "\ (And p q) = (\ p @ \ q)" - "\ (Or p q) = (\ p @ \ q)" - "\ (Eq (CN 0 c e)) = [Sub (C -1) e]" - "\ (NEq (CN 0 c e)) = [Neg e]" - "\ (Lt (CN 0 c e)) = []" - "\ (Le (CN 0 c e)) = []" - "\ (Gt (CN 0 c e)) = [Neg e]" - "\ (Ge (CN 0 c e)) = [Sub (C -1) e]" - "\ p = []" - -recdef \ "measure size" - "\ (And p q) = (\ p @ \ q)" - "\ (Or p q) = (\ p @ \ q)" - "\ (Eq (CN 0 c e)) = [Add (C -1) e]" - "\ (NEq (CN 0 c e)) = [e]" - "\ (Lt (CN 0 c e)) = [e]" - "\ (Le (CN 0 c e)) = [Add (C -1) e]" - "\ (Gt (CN 0 c e)) = []" - "\ (Ge (CN 0 c e)) = []" - "\ p = []" -consts mirror :: "fm \ fm" -recdef mirror "measure size" - "mirror (And p q) = And (mirror p) (mirror q)" - "mirror (Or p q) = Or (mirror p) (mirror q)" - "mirror (Eq (CN 0 c e)) = Eq (CN 0 c (Neg e))" - "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))" - "mirror (Lt (CN 0 c e)) = Gt (CN 0 c (Neg e))" - "mirror (Le (CN 0 c e)) = Ge (CN 0 c (Neg e))" - "mirror (Gt (CN 0 c e)) = Lt (CN 0 c (Neg e))" - "mirror (Ge (CN 0 c e)) = Le (CN 0 c (Neg e))" - "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))" - "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))" - "mirror p = p" - (* Lemmas for the correctness of \\ *) -lemma dvd1_eq1: "x >0 \ (x::int) dvd 1 = (x = 1)" -by simp - -lemma minusinf_inf: - assumes linp: "iszlfm p" - and u: "d\ p 1" - shows "\ (z::int). \ x < z. Ifm bbs (x#bs) (minusinf p) = Ifm bbs (x#bs) p" - (is "?P p" is "\ (z::int). \ x < z. ?I x (?M p) = ?I x p") -using linp u -proof (induct p rule: minusinf.induct) - case (1 p q) thus ?case - by auto (rule_tac x="min z za" in exI,simp) -next - case (2 p q) thus ?case - by auto (rule_tac x="min z za" in exI,simp) -next - case (3 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ - fix a - from 3 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \ 0" - proof(clarsimp) - fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0" - with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] - show "False" by simp - qed - thus ?case by auto -next - case (4 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ - fix a - from 4 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \ 0" - proof(clarsimp) - fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e = 0" - with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] - show "False" by simp - qed - thus ?case by auto -next - case (5 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ - fix a - from 5 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e < 0" - proof(clarsimp) - fix x assume "x < (- Inum (a#bs) e)" - with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] - show "x + Inum (x#bs) e < 0" by simp - qed - thus ?case by auto -next - case (6 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ - fix a - from 6 have "\ x<(- Inum (a#bs) e). c*x + Inum (x#bs) e \ 0" - proof(clarsimp) - fix x assume "x < (- Inum (a#bs) e)" - with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] - show "x + Inum (x#bs) e \ 0" by simp - qed - thus ?case by auto -next - case (7 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ - fix a - from 7 have "\ x<(- Inum (a#bs) e). \ (c*x + Inum (x#bs) e > 0)" - proof(clarsimp) - fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e > 0" - with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] - show "False" by simp - qed - thus ?case by auto -next - case (8 c e) hence c1: "c=1" and nb: "numbound0 e" by simp+ - fix a - from 8 have "\ x<(- Inum (a#bs) e). \ (c*x + Inum (x#bs) e \ 0)" - proof(clarsimp) - fix x assume "x < (- Inum (a#bs) e)" and"x + Inum (x#bs) e \ 0" - with numbound0_I[OF nb, where bs="bs" and b="a" and b'="x"] - show "False" by simp - qed - thus ?case by auto -qed auto - -lemma minusinf_repeats: - assumes d: "d\ p d" and linp: "iszlfm p" - shows "Ifm bbs ((x - k*d)#bs) (minusinf p) = Ifm bbs (x #bs) (minusinf p)" -using linp d -proof(induct p rule: iszlfm.induct) - case (9 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ - hence "\ k. d=i*k" by (simp add: dvd_def) - then obtain "di" where di_def: "d=i*di" by blast - show ?case - proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="x - k * d" and b'="x"] right_diff_distrib, rule iffI) - assume - "i dvd c * x - c*(k*d) + Inum (x # bs) e" - (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt") - hence "\ (l::int). ?rt = i * l" by (simp add: dvd_def) - hence "\ (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" - by (simp add: algebra_simps di_def) - hence "\ (l::int). c*x+ ?I x e = i*(l + c*k*di)" - by (simp add: algebra_simps) - hence "\ (l::int). c*x+ ?I x e = i*l" by blast - thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) - next - assume - "i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e") - hence "\ (l::int). c*x+?e = i*l" by (simp add: dvd_def) - hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp - hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def) - hence "\ (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: algebra_simps) - hence "\ (l::int). c*x - c * (k*d) +?e = i*l" - by blast - thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def) - qed -next - case (10 i c e) hence nbe: "numbound0 e" and id: "i dvd d" by simp+ - hence "\ k. d=i*k" by (simp add: dvd_def) - then obtain "di" where di_def: "d=i*di" by blast - show ?case - proof(simp add: numbound0_I[OF nbe,where bs="bs" and b="x - k * d" and b'="x"] right_diff_distrib, rule iffI) - assume - "i dvd c * x - c*(k*d) + Inum (x # bs) e" - (is "?ri dvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri dvd ?rt") - hence "\ (l::int). ?rt = i * l" by (simp add: dvd_def) - hence "\ (l::int). c*x+ ?I x e = i*l+c*(k * i*di)" - by (simp add: algebra_simps di_def) - hence "\ (l::int). c*x+ ?I x e = i*(l + c*k*di)" - by (simp add: algebra_simps) - hence "\ (l::int). c*x+ ?I x e = i*l" by blast - thus "i dvd c*x + Inum (x # bs) e" by (simp add: dvd_def) - next - assume - "i dvd c*x + Inum (x # bs) e" (is "?ri dvd ?rc*?rx+?e") - hence "\ (l::int). c*x+?e = i*l" by (simp add: dvd_def) - hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*d)" by simp - hence "\ (l::int). c*x - c*(k*d) +?e = i*l - c*(k*i*di)" by (simp add: di_def) - hence "\ (l::int). c*x - c*(k*d) +?e = i*((l - c*k*di))" by (simp add: algebra_simps) - hence "\ (l::int). c*x - c * (k*d) +?e = i*l" - by blast - thus "i dvd c*x - c*(k*d) + Inum (x # bs) e" by (simp add: dvd_def) - qed -qed (auto simp add: gr0_conv_Suc numbound0_I[where bs="bs" and b="x - k*d" and b'="x"]) - -lemma mirror\\: - assumes lp: "iszlfm p" - shows "(Inum (i#bs)) ` set (\ p) = (Inum (i#bs)) ` set (\ (mirror p))" -using lp -by (induct p rule: mirror.induct, auto) - -lemma mirror: - assumes lp: "iszlfm p" - shows "Ifm bbs (x#bs) (mirror p) = Ifm bbs ((- x)#bs) p" -using lp -proof(induct p rule: iszlfm.induct) - case (9 j c e) hence nb: "numbound0 e" by simp - have "Ifm bbs (x#bs) (mirror (Dvd j (CN 0 c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp - also have "\ = (j dvd (- (c*x - ?e)))" - by (simp only: zdvd_zminus_iff) - also have "\ = (j dvd (c* (- x)) + ?e)" - apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib) - by (simp add: algebra_simps) - also have "\ = Ifm bbs ((- x)#bs) (Dvd j (CN 0 c e))" - using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"] - by simp - finally show ?case . -next - case (10 j c e) hence nb: "numbound0 e" by simp - have "Ifm bbs (x#bs) (mirror (Dvd j (CN 0 c e))) = (j dvd c*x - Inum (x#bs) e)" (is "_ = (j dvd c*x - ?e)") by simp - also have "\ = (j dvd (- (c*x - ?e)))" - by (simp only: zdvd_zminus_iff) - also have "\ = (j dvd (c* (- x)) + ?e)" - apply (simp only: minus_mult_right[symmetric] minus_mult_left[symmetric] diff_def zadd_ac zminus_zadd_distrib) - by (simp add: algebra_simps) - also have "\ = Ifm bbs ((- x)#bs) (Dvd j (CN 0 c e))" - using numbound0_I[OF nb, where bs="bs" and b="x" and b'="- x"] - by simp - finally show ?case by simp -qed (auto simp add: numbound0_I[where bs="bs" and b="x" and b'="- x"] gr0_conv_Suc) - -lemma mirror_l: "iszlfm p \ d\ p 1 - \ iszlfm (mirror p) \ d\ (mirror p) 1" -by (induct p rule: mirror.induct, auto) - -lemma mirror_\: "iszlfm p \ \ (mirror p) = \ p" -by (induct p rule: mirror.induct,auto) - -lemma \_numbound0: assumes lp: "iszlfm p" - shows "\ b\ set (\ p). numbound0 b" - using lp by (induct p rule: \.induct,auto) - -lemma d\_mono: - assumes linp: "iszlfm p" - and dr: "d\ p l" - and d: "l dvd l'" - shows "d\ p l'" -using dr linp zdvd_trans[where n="l" and k="l'", simplified d] -by (induct p rule: iszlfm.induct) simp_all - -lemma \_l: assumes lp: "iszlfm p" - shows "\ b\ set (\ p). numbound0 b" -using lp -by(induct p rule: \.induct, auto) - -lemma \: - assumes linp: "iszlfm p" - shows "\ p > 0 \ d\ p (\ p)" -using linp -proof(induct p rule: iszlfm.induct) - case (1 p q) - from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp - from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp - from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] - d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] - dl1 dl2 show ?case by (auto simp add: zlcm_pos) -next - case (2 p q) - from prems have dl1: "\ p dvd zlcm (\ p) (\ q)" by simp - from prems have dl2: "\ q dvd zlcm (\ p) (\ q)" by simp - from prems d\_mono[where p = "p" and l="\ p" and l'="zlcm (\ p) (\ q)"] - d\_mono[where p = "q" and l="\ q" and l'="zlcm (\ p) (\ q)"] - dl1 dl2 show ?case by (auto simp add: zlcm_pos) -qed (auto simp add: zlcm_pos) - -lemma a\: assumes linp: "iszlfm p" and d: "d\ p l" and lp: "l > 0" - shows "iszlfm (a\ p l) \ d\ (a\ p l) 1 \ (Ifm bbs (l*x #bs) (a\ p l) = Ifm bbs (x#bs) p)" -using linp d -proof (induct p rule: iszlfm.induct) - case (5 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(l*x + (l div c) * Inum (x # bs) e < 0) = - ((c * (l div c)) * x + (l div c) * Inum (x # bs) e < 0)" - by simp - also have "\ = ((l div c) * (c*x + Inum (x # bs) e) < (l div c) * 0)" by (simp add: algebra_simps) - also have "\ = (c*x + Inum (x # bs) e < 0)" - using mult_less_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] be by simp -next - case (6 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(l*x + (l div c) * Inum (x# bs) e \ 0) = - ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \ 0)" - by simp - also have "\ = ((l div c) * (c * x + Inum (x # bs) e) \ ((l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (c*x + Inum (x # bs) e \ 0)" - using mult_le_0_iff [where a="(l div c)" and b="c*x + Inum (x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] be by simp -next - case (7 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(l*x + (l div c)* Inum (x # bs) e > 0) = - ((c * (l div c)) * x + (l div c) * Inum (x # bs) e > 0)" - by simp - also have "\ = ((l div c) * (c * x + Inum (x # bs) e) > ((l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (c * x + Inum (x # bs) e > 0)" - using zero_less_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be by simp -next - case (8 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(l*x + (l div c)* Inum (x # bs) e \ 0) = - ((c*(l div c))*x + (l div c)* Inum (x # bs) e \ 0)" - by simp - also have "\ = ((l div c)*(c*x + Inum (x # bs) e) \ ((l div c)) * 0)" - by (simp add: algebra_simps) - also have "\ = (c*x + Inum (x # bs) e \ 0)" using ldcp - zero_le_mult_iff [where a="l div c" and b="c*x + Inum (x # bs) e"] by simp - finally show ?case using be numbound0_I[OF be,where b="l*x" and b'="x" and bs="bs"] - by simp -next - case (3 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(l * x + (l div c) * Inum (x # bs) e = 0) = - ((c * (l div c)) * x + (l div c) * Inum (x # bs) e = 0)" - by simp - also have "\ = ((l div c) * (c * x + Inum (x # bs) e) = ((l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (c * x + Inum (x # bs) e = 0)" - using mult_eq_0_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be by simp -next - case (4 c e) hence cp: "c>0" and be: "numbound0 e" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(l * x + (l div c) * Inum (x # bs) e \ 0) = - ((c * (l div c)) * x + (l div c) * Inum (x # bs) e \ 0)" - by simp - also have "\ = ((l div c) * (c * x + Inum (x # bs) e) \ ((l div c)) * 0)" by (simp add: algebra_simps) - also have "\ = (c * x + Inum (x # bs) e \ 0)" - using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e"] ldcp by simp - finally show ?case using numbound0_I[OF be,where b="(l * x)" and b'="x" and bs="bs"] be by simp -next - case (9 j c e) hence cp: "c>0" and be: "numbound0 e" and jp: "j > 0" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(\ (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\ (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)" by simp - also have "\ = (\ (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: algebra_simps) - also fix k have "\ = (\ (k::int). c * x + Inum (x # bs) e - j * k = 0)" - using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp - also have "\ = (\ (k::int). c * x + Inum (x # bs) e = j * k)" by simp - 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) -next - case (10 j c e) hence cp: "c>0" and be: "numbound0 e" and jp: "j > 0" and d': "c dvd l" by simp+ - from lp cp have clel: "c\l" by (simp add: zdvd_imp_le [OF d' lp]) - from cp have cnz: "c \ 0" by simp - have "c div c\ l div c" - by (simp add: zdiv_mono1[OF clel cp]) - then have ldcp:"0 < l div c" - by (simp add: zdiv_self[OF cnz]) - 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 - hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] - by simp - hence "(\ (k::int). l * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k) = (\ (k::int). (c * (l div c)) * x + (l div c) * Inum (x # bs) e = ((l div c) * j) * k)" by simp - also have "\ = (\ (k::int). (l div c) * (c * x + Inum (x # bs) e - j * k) = (l div c)*0)" by (simp add: algebra_simps) - also fix k have "\ = (\ (k::int). c * x + Inum (x # bs) e - j * k = 0)" - using zero_le_mult_iff [where a="(l div c)" and b="c * x + Inum (x # bs) e - j * k"] ldcp by simp - also have "\ = (\ (k::int). c * x + Inum (x # bs) e = j * k)" by simp - 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) -qed (auto simp add: gr0_conv_Suc numbound0_I[where bs="bs" and b="(l * x)" and b'="x"]) - -lemma a\_ex: assumes linp: "iszlfm p" and d: "d\ p l" and lp: "l>0" - shows "(\ x. l dvd x \ Ifm bbs (x #bs) (a\ p l)) = (\ (x::int). Ifm bbs (x#bs) p)" - (is "(\ x. l dvd x \ ?P x) = (\ x. ?P' x)") -proof- - have "(\ x. l dvd x \ ?P x) = (\ (x::int). ?P (l*x))" - using unity_coeff_ex[where l="l" and P="?P", simplified] by simp - also have "\ = (\ (x::int). ?P' x)" using a\[OF linp d lp] by simp - finally show ?thesis . -qed - -lemma \: - assumes lp: "iszlfm p" - and u: "d\ p 1" - and d: "d\ p d" - and dp: "d > 0" - and nob: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). x = b + j)" - and p: "Ifm bbs (x#bs) p" (is "?P x") - shows "?P (x - d)" -using lp u d dp nob p -proof(induct p rule: iszlfm.induct) - case (5 c e) hence c1: "c=1" and bn:"numbound0 e" by simp+ - with dp p c1 numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] prems - show ?case by simp -next - case (6 c e) hence c1: "c=1" and bn:"numbound0 e" by simp+ - with dp p c1 numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] prems - show ?case by simp -next - case (7 c e) hence p: "Ifm bbs (x #bs) (Gt (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" by simp+ - let ?e = "Inum (x # bs) e" - {assume "(x-d) +?e > 0" hence ?case using c1 - numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] by simp} - moreover - {assume H: "\ (x-d) + ?e > 0" - let ?v="Neg e" - have vb: "?v \ set (\ (Gt (CN 0 c e)))" by simp - from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="x" and bs="bs"]] - have nob: "\ (\ j\ {1 ..d}. x = - ?e + j)" by auto - from H p have "x + ?e > 0 \ x + ?e \ d" by (simp add: c1) - hence "x + ?e \ 1 \ x + ?e \ d" by simp - hence "\ (j::int) \ {1 .. d}. j = x + ?e" by simp - hence "\ (j::int) \ {1 .. d}. x = (- ?e + j)" - by (simp add: algebra_simps) - with nob have ?case by auto} - ultimately show ?case by blast -next - case (8 c e) hence p: "Ifm bbs (x #bs) (Ge (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" - by simp+ - let ?e = "Inum (x # bs) e" - {assume "(x-d) +?e \ 0" hence ?case using c1 - numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] - by simp} - moreover - {assume H: "\ (x-d) + ?e \ 0" - let ?v="Sub (C -1) e" - have vb: "?v \ set (\ (Ge (CN 0 c e)))" by simp - from prems(11)[simplified simp_thms Inum.simps \.simps set.simps bex_simps numbound0_I[OF bn,where b="a" and b'="x" and bs="bs"]] - have nob: "\ (\ j\ {1 ..d}. x = - ?e - 1 + j)" by auto - from H p have "x + ?e \ 0 \ x + ?e < d" by (simp add: c1) - hence "x + ?e +1 \ 1 \ x + ?e + 1 \ d" by simp - hence "\ (j::int) \ {1 .. d}. j = x + ?e + 1" by simp - hence "\ (j::int) \ {1 .. d}. x= - ?e - 1 + j" by (simp add: algebra_simps) - with nob have ?case by simp } - ultimately show ?case by blast -next - case (3 c e) hence p: "Ifm bbs (x #bs) (Eq (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ - let ?e = "Inum (x # bs) e" - let ?v="(Sub (C -1) e)" - have vb: "?v \ set (\ (Eq (CN 0 c e)))" by simp - from p have "x= - ?e" by (simp add: c1) with prems(11) show ?case using dp - by simp (erule ballE[where x="1"], - simp_all add:algebra_simps numbound0_I[OF bn,where b="x"and b'="a"and bs="bs"]) -next - case (4 c e)hence p: "Ifm bbs (x #bs) (NEq (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ - let ?e = "Inum (x # bs) e" - let ?v="Neg e" - have vb: "?v \ set (\ (NEq (CN 0 c e)))" by simp - {assume "x - d + Inum (((x -d)) # bs) e \ 0" - hence ?case by (simp add: c1)} - moreover - {assume H: "x - d + Inum (((x -d)) # bs) e = 0" - hence "x = - Inum (((x -d)) # bs) e + d" by simp - hence "x = - Inum (a # bs) e + d" - by (simp add: numbound0_I[OF bn,where b="x - d"and b'="a"and bs="bs"]) - with prems(11) have ?case using dp by simp} - ultimately show ?case by blast -next - case (9 j c e) hence p: "Ifm bbs (x #bs) (Dvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ - let ?e = "Inum (x # bs) e" - from prems have id: "j dvd d" by simp - from c1 have "?p x = (j dvd (x+ ?e))" by simp - also have "\ = (j dvd x - d + ?e)" - using zdvd_period[OF id, where x="x" and c="-1" and t="?e"] by simp - finally show ?case - using numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] c1 p by simp -next - case (10 j c e) hence p: "Ifm bbs (x #bs) (NDvd j (CN 0 c e))" (is "?p x") and c1: "c=1" and bn:"numbound0 e" by simp+ - let ?e = "Inum (x # bs) e" - from prems have id: "j dvd d" by simp - from c1 have "?p x = (\ j dvd (x+ ?e))" by simp - also have "\ = (\ j dvd x - d + ?e)" - using zdvd_period[OF id, where x="x" and c="-1" and t="?e"] by simp - finally show ?case using numbound0_I[OF bn,where b="(x-d)" and b'="x" and bs="bs"] c1 p by simp -qed (auto simp add: numbound0_I[where bs="bs" and b="(x - d)" and b'="x"] gr0_conv_Suc) - -lemma \': - assumes lp: "iszlfm p" - and u: "d\ p 1" - and d: "d\ p d" - and dp: "d > 0" - shows "\ x. \(\(j::int) \ {1 .. d}. \ b\ set(\ p). Ifm bbs ((Inum (a#bs) b + j) #bs) p) \ Ifm bbs (x#bs) p \ Ifm bbs ((x - d)#bs) p" (is "\ x. ?b \ ?P x \ ?P (x - d)") -proof(clarify) - fix x - assume nb:"?b" and px: "?P x" - hence nb2: "\(\(j::int) \ {1 .. d}. \ b\ (Inum (a#bs)) ` set(\ p). x = b + j)" - by auto - from \[OF lp u d dp nb2 px] show "?P (x -d )" . -qed -lemma cpmi_eq: "0 < D \ (EX z::int. ALL x. x < z --> (P x = P1 x)) -==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) -==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D)))) -==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))" -apply(rule iffI) -prefer 2 -apply(drule minusinfinity) -apply assumption+ -apply(fastsimp) -apply clarsimp -apply(subgoal_tac "!!k. 0<=k \ !x. P x \ P (x - k*D)") -apply(frule_tac x = x and z=z in decr_lemma) -apply(subgoal_tac "P1(x - (\x - z\ + 1) * D)") -prefer 2 -apply(subgoal_tac "0 <= (\x - z\ + 1)") -prefer 2 apply arith - apply fastsimp -apply(drule (1) periodic_finite_ex) -apply blast -apply(blast dest:decr_mult_lemma) -done - -theorem cp_thm: - assumes lp: "iszlfm p" - and u: "d\ p 1" - and d: "d\ p d" - and dp: "d > 0" - shows "(\ (x::int). Ifm bbs (x #bs) p) = (\ j\ {1.. d}. Ifm bbs (j #bs) (minusinf p) \ (\ b \ set (\ p). Ifm bbs ((Inum (i#bs) b + j) #bs) p))" - (is "(\ (x::int). ?P (x)) = (\ j\ ?D. ?M j \ (\ b\ ?B. ?P (?I b + j)))") -proof- - from minusinf_inf[OF lp u] - have th: "\(z::int). \xj\?D. \b\ ?B. ?P (?I b +j)) = (\ j \ ?D. \ b \ ?B'. ?P (b + j))" by auto - hence th2: "\ x. \ (\ j \ ?D. \ b \ ?B'. ?P ((b + j))) \ ?P (x) \ ?P ((x - d))" - using \'[OF lp u d dp, where a="i" and bbs = "bbs"] by blast - from minusinf_repeats[OF d lp] - have th3: "\ x k. ?M x = ?M (x-k*d)" by simp - from cpmi_eq[OF dp th th2 th3] BB' show ?thesis by blast -qed - - (* Implement the right hand sides of Cooper's theorem and Ferrante and Rackoff. *) -lemma mirror_ex: - assumes lp: "iszlfm p" - shows "(\ x. Ifm bbs (x#bs) (mirror p)) = (\ x. Ifm bbs (x#bs) p)" - (is "(\ x. ?I x ?mp) = (\ x. ?I x p)") -proof(auto) - fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast - thus "\ x. ?I x p" by blast -next - fix x assume "?I x p" hence "?I (- x) ?mp" - using mirror[OF lp, where x="- x", symmetric] by auto - thus "\ x. ?I x ?mp" by blast -qed - - -lemma cp_thm': - assumes lp: "iszlfm p" - and up: "d\ p 1" and dd: "d\ p d" and dp: "d > 0" - shows "(\ x. Ifm bbs (x#bs) p) = ((\ j\ {1 .. d}. Ifm bbs (j#bs) (minusinf p)) \ (\ j\ {1.. d}. \ b\ (Inum (i#bs)) ` set (\ p). Ifm bbs ((b+j)#bs) p))" - using cp_thm[OF lp up dd dp,where i="i"] by auto - -constdefs unit:: "fm \ fm \ num list \ int" - "unit p \ (let p' = zlfm p ; l = \ p' ; q = And (Dvd l (CN 0 1 (C 0))) (a\ p' l); d = \ q; - B = remdups (map simpnum (\ q)) ; a = remdups (map simpnum (\ q)) - in if length B \ length a then (q,B,d) else (mirror q, a,d))" - -lemma unit: assumes qf: "qfree p" - shows "\ q B d. unit p = (q,B,d) \ ((\ x. Ifm bbs (x#bs) p) = (\ x. Ifm bbs (x#bs) q)) \ (Inum (i#bs)) ` set B = (Inum (i#bs)) ` set (\ q) \ d\ q 1 \ d\ q d \ d >0 \ iszlfm q \ (\ b\ set B. numbound0 b)" -proof- - fix q B d - assume qBd: "unit p = (q,B,d)" - let ?thes = "((\ x. Ifm bbs (x#bs) p) = (\ x. Ifm bbs (x#bs) q)) \ - Inum (i#bs) ` set B = Inum (i#bs) ` set (\ q) \ - d\ q 1 \ d\ q d \ 0 < d \ iszlfm q \ (\ b\ set B. numbound0 b)" - let ?I = "\ x p. Ifm bbs (x#bs) p" - let ?p' = "zlfm p" - let ?l = "\ ?p'" - let ?q = "And (Dvd ?l (CN 0 1 (C 0))) (a\ ?p' ?l)" - let ?d = "\ ?q" - let ?B = "set (\ ?q)" - let ?B'= "remdups (map simpnum (\ ?q))" - let ?A = "set (\ ?q)" - let ?A'= "remdups (map simpnum (\ ?q))" - from conjunct1[OF zlfm_I[OF qf, where bs="bs"]] - have pp': "\ i. ?I i ?p' = ?I i p" by auto - from conjunct2[OF zlfm_I[OF qf, where bs="bs" and i="i"]] - have lp': "iszlfm ?p'" . - from lp' \[where p="?p'"] have lp: "?l >0" and dl: "d\ ?p' ?l" by auto - from a\_ex[where p="?p'" and l="?l" and bs="bs", OF lp' dl lp] pp' - have pq_ex:"(\ (x::int). ?I x p) = (\ x. ?I x ?q)" by simp - from lp' lp a\[OF lp' dl lp] have lq:"iszlfm ?q" and uq: "d\ ?q 1" by auto - from \[OF lq] have dp:"?d >0" and dd: "d\ ?q ?d" by blast+ - let ?N = "\ t. Inum (i#bs) t" - have "?N ` set ?B' = ((?N o simpnum) ` ?B)" by auto - also have "\ = ?N ` ?B" using simpnum_ci[where bs="i#bs"] by auto - finally have BB': "?N ` set ?B' = ?N ` ?B" . - have "?N ` set ?A' = ((?N o simpnum) ` ?A)" by auto - also have "\ = ?N ` ?A" using simpnum_ci[where bs="i#bs"] by auto - finally have AA': "?N ` set ?A' = ?N ` ?A" . - from \_numbound0[OF lq] have B_nb:"\ b\ set ?B'. numbound0 b" - by (simp add: simpnum_numbound0) - from \_l[OF lq] have A_nb: "\ b\ set ?A'. numbound0 b" - by (simp add: simpnum_numbound0) - {assume "length ?B' \ length ?A'" - hence q:"q=?q" and "B = ?B'" and d:"d = ?d" - using qBd by (auto simp add: Let_def unit_def) - with BB' B_nb have b: "?N ` (set B) = ?N ` set (\ q)" - and bn: "\b\ set B. numbound0 b" by simp+ - with pq_ex dp uq dd lq q d have ?thes by simp} - moreover - {assume "\ (length ?B' \ length ?A')" - hence q:"q=mirror ?q" and "B = ?A'" and d:"d = ?d" - using qBd by (auto simp add: Let_def unit_def) - with AA' mirror\\[OF lq] A_nb have b:"?N ` (set B) = ?N ` set (\ q)" - and bn: "\b\ set B. numbound0 b" by simp+ - from mirror_ex[OF lq] pq_ex q - have pqm_eq:"(\ (x::int). ?I x p) = (\ (x::int). ?I x q)" by simp - from lq uq q mirror_l[where p="?q"] - have lq': "iszlfm q" and uq: "d\ q 1" by auto - from \[OF lq'] mirror_\[OF lq] q d have dq:"d\ q d " by auto - from pqm_eq b bn uq lq' dp dq q dp d have ?thes by simp - } - ultimately show ?thes by blast -qed - (* Cooper's Algorithm *) - -constdefs cooper :: "fm \ fm" - "cooper p \ - (let (q,B,d) = unit p; js = iupt 1 d; - mq = simpfm (minusinf q); - md = evaldjf (\ j. simpfm (subst0 (C j) mq)) js - in if md = T then T else - (let qd = evaldjf (\ (b,j). simpfm (subst0 (Add b (C j)) q)) - [(b,j). b\B,j\js] - in decr (disj md qd)))" -lemma cooper: assumes qf: "qfree p" - shows "((\ x. Ifm bbs (x#bs) p) = (Ifm bbs bs (cooper p))) \ qfree (cooper p)" - (is "(?lhs = ?rhs) \ _") -proof- - let ?I = "\ x p. Ifm bbs (x#bs) p" - let ?q = "fst (unit p)" - let ?B = "fst (snd(unit p))" - let ?d = "snd (snd (unit p))" - let ?js = "iupt 1 ?d" - let ?mq = "minusinf ?q" - let ?smq = "simpfm ?mq" - let ?md = "evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js" - fix i - let ?N = "\ t. Inum (i#bs) t" - let ?Bjs = "[(b,j). b\?B,j\?js]" - let ?qd = "evaldjf (\ (b,j). simpfm (subst0 (Add b (C j)) ?q)) ?Bjs" - have qbf:"unit p = (?q,?B,?d)" by simp - from unit[OF qf qbf] have pq_ex: "(\(x::int). ?I x p) = (\ (x::int). ?I x ?q)" and - B:"?N ` set ?B = ?N ` set (\ ?q)" and - uq:"d\ ?q 1" and dd: "d\ ?q ?d" and dp: "?d > 0" and - lq: "iszlfm ?q" and - Bn: "\ b\ set ?B. numbound0 b" by auto - from zlin_qfree[OF lq] have qfq: "qfree ?q" . - from simpfm_qf[OF minusinf_qfree[OF qfq]] have qfmq: "qfree ?smq". - have jsnb: "\ j \ set ?js. numbound0 (C j)" by simp - hence "\ j\ set ?js. bound0 (subst0 (C j) ?smq)" - by (auto simp only: subst0_bound0[OF qfmq]) - hence th: "\ j\ set ?js. bound0 (simpfm (subst0 (C j) ?smq))" - by (auto simp add: simpfm_bound0) - from evaldjf_bound0[OF th] have mdb: "bound0 ?md" by simp - from Bn jsnb have "\ (b,j) \ set ?Bjs. numbound0 (Add b (C j))" - by simp - hence "\ (b,j) \ set ?Bjs. bound0 (subst0 (Add b (C j)) ?q)" - using subst0_bound0[OF qfq] by blast - hence "\ (b,j) \ set ?Bjs. bound0 (simpfm (subst0 (Add b (C j)) ?q))" - using simpfm_bound0 by blast - hence th': "\ x \ set ?Bjs. bound0 ((\ (b,j). simpfm (subst0 (Add b (C j)) ?q)) x)" - by auto - from evaldjf_bound0 [OF th'] have qdb: "bound0 ?qd" by simp - from mdb qdb - have mdqdb: "bound0 (disj ?md ?qd)" by (simp only: disj_def, cases "?md=T \ ?qd=T", simp_all) - from trans [OF pq_ex cp_thm'[OF lq uq dd dp,where i="i"]] B - have "?lhs = (\ j\ {1.. ?d}. ?I j ?mq \ (\ b\ ?N ` set ?B. Ifm bbs ((b+ j)#bs) ?q))" by auto - also have "\ = (\ j\ {1.. ?d}. ?I j ?mq \ (\ b\ set ?B. Ifm bbs ((?N b+ j)#bs) ?q))" by simp - also have "\ = ((\ j\ {1.. ?d}. ?I j ?mq ) \ (\ j\ {1.. ?d}. \ b\ set ?B. Ifm bbs ((?N (Add b (C j)))#bs) ?q))" by (simp only: Inum.simps) blast - also have "\ = ((\ j\ {1.. ?d}. ?I j ?smq ) \ (\ j\ {1.. ?d}. \ b\ set ?B. Ifm bbs ((?N (Add b (C j)))#bs) ?q))" by (simp add: simpfm) - also have "\ = ((\ j\ set ?js. (\ j. ?I i (simpfm (subst0 (C j) ?smq))) j) \ (\ j\ set ?js. \ b\ set ?B. Ifm bbs ((?N (Add b (C j)))#bs) ?q))" - by (simp only: simpfm subst0_I[OF qfmq] iupt_set) auto - also have "\ = (?I i (evaldjf (\ j. simpfm (subst0 (C j) ?smq)) ?js) \ (\ j\ set ?js. \ b\ set ?B. ?I i (subst0 (Add b (C j)) ?q)))" - by (simp only: evaldjf_ex subst0_I[OF qfq]) - also have "\= (?I i ?md \ (\ (b,j) \ set ?Bjs. (\ (b,j). ?I i (simpfm (subst0 (Add b (C j)) ?q))) (b,j)))" - by (simp only: simpfm set_concat set_map concat_map_singleton UN_simps) blast - also have "\ = (?I i ?md \ (?I i (evaldjf (\ (b,j). simpfm (subst0 (Add b (C j)) ?q)) ?Bjs)))" - by (simp only: evaldjf_ex[where bs="i#bs" and f="\ (b,j). simpfm (subst0 (Add b (C j)) ?q)" and ps="?Bjs"]) (auto simp add: split_def) - finally have mdqd: "?lhs = (?I i ?md \ ?I i ?qd)" by simp - also have "\ = (?I i (disj ?md ?qd))" by (simp add: disj) - also have "\ = (Ifm bbs bs (decr (disj ?md ?qd)))" by (simp only: decr [OF mdqdb]) - finally have mdqd2: "?lhs = (Ifm bbs bs (decr (disj ?md ?qd)))" . - {assume mdT: "?md = T" - hence cT:"cooper p = T" - by (simp only: cooper_def unit_def split_def Let_def if_True) simp - from mdT have lhs:"?lhs" using mdqd by simp - from mdT have "?rhs" by (simp add: cooper_def unit_def split_def) - with lhs cT have ?thesis by simp } - moreover - {assume mdT: "?md \ T" hence "cooper p = decr (disj ?md ?qd)" - by (simp only: cooper_def unit_def split_def Let_def if_False) - with mdqd2 decr_qf[OF mdqdb] have ?thesis by simp } - ultimately show ?thesis by blast -qed - -definition pa :: "fm \ fm" where - "pa p = qelim (prep p) cooper" - -theorem mirqe: "(Ifm bbs bs (pa p) = Ifm bbs bs p) \ qfree (pa p)" - using qelim_ci cooper prep by (auto simp add: pa_def) - -definition - cooper_test :: "unit \ fm" -where - "cooper_test u = pa (E (A (Imp (Ge (Sub (Bound 0) (Bound 1))) - (E (E (Eq (Sub (Add (Mul 3 (Bound 1)) (Mul 5 (Bound 0))) - (Bound 2))))))))" - -ML {* @{code cooper_test} () *} - -(* -code_reserved SML oo -export_code pa in SML module_name GeneratedCooper file "~~/src/HOL/Tools/Qelim/raw_generated_cooper.ML" -*) - -oracle linzqe_oracle = {* -let - -fun num_of_term vs (t as Free (xn, xT)) = (case AList.lookup (op =) vs t - of NONE => error "Variable not found in the list!" - | SOME n => @{code Bound} n) - | num_of_term vs @{term "0::int"} = @{code C} 0 - | num_of_term vs @{term "1::int"} = @{code C} 1 - | num_of_term vs (@{term "number_of :: int \ int"} $ t) = @{code C} (HOLogic.dest_numeral t) - | num_of_term vs (Bound i) = @{code Bound} i - | num_of_term vs (@{term "uminus :: int \ int"} $ t') = @{code Neg} (num_of_term vs t') - | num_of_term vs (@{term "op + :: int \ int \ int"} $ t1 $ t2) = - @{code Add} (num_of_term vs t1, num_of_term vs t2) - | num_of_term vs (@{term "op - :: int \ int \ int"} $ t1 $ t2) = - @{code Sub} (num_of_term vs t1, num_of_term vs t2) - | num_of_term vs (@{term "op * :: int \ int \ int"} $ t1 $ t2) = - (case try HOLogic.dest_number t1 - of SOME (_, i) => @{code Mul} (i, num_of_term vs t2) - | NONE => (case try HOLogic.dest_number t2 - of SOME (_, i) => @{code Mul} (i, num_of_term vs t1) - | NONE => error "num_of_term: unsupported multiplication")) - | num_of_term vs t = error ("num_of_term: unknown term " ^ Syntax.string_of_term @{context} t); - -fun fm_of_term ps vs @{term True} = @{code T} - | fm_of_term ps vs @{term False} = @{code F} - | fm_of_term ps vs (@{term "op < :: int \ int \ bool"} $ t1 $ t2) = - @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term ps vs (@{term "op \ :: int \ int \ bool"} $ t1 $ t2) = - @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term ps vs (@{term "op = :: int \ int \ bool"} $ t1 $ t2) = - @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) - | fm_of_term ps vs (@{term "op dvd :: int \ int \ bool"} $ t1 $ t2) = - (case try HOLogic.dest_number t1 - of SOME (_, i) => @{code Dvd} (i, num_of_term vs t2) - | NONE => error "num_of_term: unsupported dvd") - | fm_of_term ps vs (@{term "op = :: bool \ bool \ bool"} $ t1 $ t2) = - @{code Iff} (fm_of_term ps vs t1, fm_of_term ps vs t2) - | fm_of_term ps vs (@{term "op &"} $ t1 $ t2) = - @{code And} (fm_of_term ps vs t1, fm_of_term ps vs t2) - | fm_of_term ps vs (@{term "op |"} $ t1 $ t2) = - @{code Or} (fm_of_term ps vs t1, fm_of_term ps vs t2) - | fm_of_term ps vs (@{term "op -->"} $ t1 $ t2) = - @{code Imp} (fm_of_term ps vs t1, fm_of_term ps vs t2) - | fm_of_term ps vs (@{term "Not"} $ t') = - @{code NOT} (fm_of_term ps vs t') - | fm_of_term ps vs (Const ("Ex", _) $ Abs (xn, xT, p)) = - let - val (xn', p') = variant_abs (xn, xT, p); - val vs' = (Free (xn', xT), 0) :: map (fn (v, n) => (v, n + 1)) vs; - in @{code E} (fm_of_term ps vs' p) end - | fm_of_term ps vs (Const ("All", _) $ Abs (xn, xT, p)) = - let - val (xn', p') = variant_abs (xn, xT, p); - val vs' = (Free (xn', xT), 0) :: map (fn (v, n) => (v, n + 1)) vs; - in @{code A} (fm_of_term ps vs' p) end - | fm_of_term ps vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); - -fun term_of_num vs (@{code C} i) = HOLogic.mk_number HOLogic.intT i - | term_of_num vs (@{code Bound} n) = fst (the (find_first (fn (_, m) => n = m) vs)) - | term_of_num vs (@{code Neg} t') = @{term "uminus :: int \ int"} $ term_of_num vs t' - | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: int \ int \ int"} $ - term_of_num vs t1 $ term_of_num vs t2 - | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: int \ int \ int"} $ - term_of_num vs t1 $ term_of_num vs t2 - | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: int \ int \ int"} $ - term_of_num vs (@{code C} i) $ term_of_num vs t2 - | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)) - -fun term_of_fm ps vs @{code T} = HOLogic.true_const - | term_of_fm ps vs @{code F} = HOLogic.false_const - | term_of_fm ps vs (@{code Lt} t) = - @{term "op < :: int \ int \ bool"} $ term_of_num vs t $ @{term "0::int"} - | term_of_fm ps vs (@{code Le} t) = - @{term "op \ :: int \ int \ bool"} $ term_of_num vs t $ @{term "0::int"} - | term_of_fm ps vs (@{code Gt} t) = - @{term "op < :: int \ int \ bool"} $ @{term "0::int"} $ term_of_num vs t - | term_of_fm ps vs (@{code Ge} t) = - @{term "op \ :: int \ int \ bool"} $ @{term "0::int"} $ term_of_num vs t - | term_of_fm ps vs (@{code Eq} t) = - @{term "op = :: int \ int \ bool"} $ term_of_num vs t $ @{term "0::int"} - | term_of_fm ps vs (@{code NEq} t) = - term_of_fm ps vs (@{code NOT} (@{code Eq} t)) - | term_of_fm ps vs (@{code Dvd} (i, t)) = - @{term "op dvd :: int \ int \ bool"} $ term_of_num vs (@{code C} i) $ term_of_num vs t - | term_of_fm ps vs (@{code NDvd} (i, t)) = - term_of_fm ps vs (@{code NOT} (@{code Dvd} (i, t))) - | term_of_fm ps vs (@{code NOT} t') = - HOLogic.Not $ term_of_fm ps vs t' - | term_of_fm ps vs (@{code And} (t1, t2)) = - HOLogic.conj $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 - | term_of_fm ps vs (@{code Or} (t1, t2)) = - HOLogic.disj $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 - | term_of_fm ps vs (@{code Imp} (t1, t2)) = - HOLogic.imp $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 - | term_of_fm ps vs (@{code Iff} (t1, t2)) = - @{term "op = :: bool \ bool \ bool"} $ term_of_fm ps vs t1 $ term_of_fm ps vs t2 - | term_of_fm ps vs (@{code Closed} n) = (fst o the) (find_first (fn (_, m) => m = n) ps) - | term_of_fm ps vs (@{code NClosed} n) = term_of_fm ps vs (@{code NOT} (@{code Closed} n)) - -fun term_bools acc t = - let - val is_op = member (op =) [@{term "op &"}, @{term "op |"}, @{term "op -->"}, @{term "op = :: bool => _"}, - @{term "op = :: int => _"}, @{term "op < :: int => _"}, - @{term "op <= :: int => _"}, @{term "Not"}, @{term "All :: (int => _) => _"}, - @{term "Ex :: (int => _) => _"}, @{term "True"}, @{term "False"}] - fun is_ty t = not (fastype_of t = HOLogic.boolT) - in case t - of (l as f $ a) $ b => if is_ty t orelse is_op t then term_bools (term_bools acc l)b - else insert (op aconv) t acc - | f $ a => if is_ty t orelse is_op t then term_bools (term_bools acc f) a - else insert (op aconv) t acc - | Abs p => term_bools acc (snd (variant_abs p)) - | _ => if is_ty t orelse is_op t then acc else insert (op aconv) t acc - end; - -in fn ct => - let - val thy = Thm.theory_of_cterm ct; - val t = Thm.term_of ct; - val fs = OldTerm.term_frees t; - val bs = term_bools [] t; - val vs = fs ~~ (0 upto (length fs - 1)) - val ps = bs ~~ (0 upto (length bs - 1)) - val t' = (term_of_fm ps vs o @{code pa} o fm_of_term ps vs) t; - in (Thm.cterm_of thy o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end -end; -*} - -use "coopertac.ML" -setup "LinZTac.setup" - -text {* Tests *} - -lemma "\ (j::int). \ x\j. (\ a b. x = 3*a+5*b)" - by cooper - -lemma "ALL (x::int) >=8. EX i j. 5*i + 3*j = x" - by cooper - -theorem "(\(y::int). 3 dvd y) ==> \(x::int). b < x --> a \ x" - by cooper - -theorem "!! (y::int) (z::int) (n::int). 3 dvd z ==> 2 dvd (y::int) ==> - (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" - by cooper - -theorem "!! (y::int) (z::int) n. Suc(n::nat) < 6 ==> 3 dvd z ==> - 2 dvd (y::int) ==> (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" - by cooper - -theorem "\(x::nat). \(y::nat). (0::nat) \ 5 --> y = 5 + x " - by cooper - -lemma "ALL (x::int) >=8. EX i j. 5*i + 3*j = x" - by cooper - -lemma "ALL (y::int) (z::int) (n::int). 3 dvd z --> 2 dvd (y::int) --> (EX (x::int). 2*x = y) & (EX (k::int). 3*k = z)" - by cooper - -lemma "ALL(x::int) y. x < y --> 2 * x + 1 < 2 * y" - by cooper - -lemma "ALL(x::int) y. 2 * x + 1 ~= 2 * y" - by cooper - -lemma "EX(x::int) y. 0 < x & 0 <= y & 3 * x - 5 * y = 1" - by cooper - -lemma "~ (EX(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)" - by cooper - -lemma "ALL(x::int). (2 dvd x) --> (EX(y::int). x = 2*y)" - by cooper - -lemma "ALL(x::int). (2 dvd x) = (EX(y::int). x = 2*y)" - by cooper - -lemma "ALL(x::int). ((2 dvd x) = (ALL(y::int). x ~= 2*y + 1))" - by cooper - -lemma "~ (ALL(x::int). ((2 dvd x) = (ALL(y::int). x ~= 2*y+1) | (EX(q::int) (u::int) i. 3*i + 2*q - u < 17) --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))" - by cooper - -lemma "~ (ALL(i::int). 4 <= i --> (EX x y. 0 <= x & 0 <= y & 3 * x + 5 * y = i))" - by cooper - -lemma "EX j. ALL (x::int) >= j. EX i j. 5*i + 3*j = x" - by cooper - -theorem "(\(y::int). 3 dvd y) ==> \(x::int). b < x --> a \ x" - by cooper - -theorem "!! (y::int) (z::int) (n::int). 3 dvd z ==> 2 dvd (y::int) ==> - (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" - by cooper - -theorem "!! (y::int) (z::int) n. Suc(n::nat) < 6 ==> 3 dvd z ==> - 2 dvd (y::int) ==> (\(x::int). 2*x = y) & (\(k::int). 3*k = z)" - by cooper - -theorem "\(x::nat). \(y::nat). (0::nat) \ 5 --> y = 5 + x " - by cooper - -theorem "\(x::nat). \(y::nat). y = 5 + x | x div 6 + 1= 2" - by cooper - -theorem "\(x::int). 0 < x" - by cooper - -theorem "\(x::int) y. x < y --> 2 * x + 1 < 2 * y" - by cooper - -theorem "\(x::int) y. 2 * x + 1 \ 2 * y" - by cooper - -theorem "\(x::int) y. 0 < x & 0 \ y & 3 * x - 5 * y = 1" - by cooper - -theorem "~ (\(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)" - by cooper - -theorem "~ (\(x::int). False)" - by cooper - -theorem "\(x::int). (2 dvd x) --> (\(y::int). x = 2*y)" - by cooper - -theorem "\(x::int). (2 dvd x) --> (\(y::int). x = 2*y)" - by cooper - -theorem "\(x::int). (2 dvd x) = (\(y::int). x = 2*y)" - by cooper - -theorem "\(x::int). ((2 dvd x) = (\(y::int). x \ 2*y + 1))" - by cooper - -theorem "~ (\(x::int). - ((2 dvd x) = (\(y::int). x \ 2*y+1) | - (\(q::int) (u::int) i. 3*i + 2*q - u < 17) - --> 0 < x | ((~ 3 dvd x) &(x + 8 = 0))))" - by cooper - -theorem "~ (\(i::int). 4 \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i))" - by cooper - -theorem "\(i::int). 8 \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i)" - by cooper - -theorem "\(j::int). \i. j \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i)" - by cooper - -theorem "~ (\j (i::int). j \ i --> (\x y. 0 \ x & 0 \ y & 3 * x + 5 * y = i))" - by cooper - -theorem "(\m::nat. n = 2 * m) --> (n + 1) div 2 = n div 2" - by cooper - -end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/coopertac.ML --- a/src/HOL/ex/coopertac.ML Tue Feb 03 16:50:40 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -structure LinZTac = -struct - -val trace = ref false; -fun trace_msg s = if !trace then tracing s else (); - -val cooper_ss = @{simpset}; - -val nT = HOLogic.natT; -val binarith = @{thms normalize_bin_simps}; -val comp_arith = binarith @ simp_thms - -val zdvd_int = @{thm zdvd_int}; -val zdiff_int_split = @{thm zdiff_int_split}; -val all_nat = @{thm all_nat}; -val ex_nat = @{thm ex_nat}; -val number_of1 = @{thm number_of1}; -val number_of2 = @{thm number_of2}; -val split_zdiv = @{thm split_zdiv}; -val split_zmod = @{thm split_zmod}; -val mod_div_equality' = @{thm mod_div_equality'}; -val split_div' = @{thm split_div'}; -val Suc_plus1 = @{thm Suc_plus1}; -val imp_le_cong = @{thm imp_le_cong}; -val conj_le_cong = @{thm conj_le_cong}; -val nat_mod_add_eq = @{thm mod_add1_eq} RS sym; -val nat_mod_add_left_eq = @{thm mod_add_left_eq} RS sym; -val nat_mod_add_right_eq = @{thm mod_add_right_eq} RS sym; -val int_mod_add_eq = @{thm zmod_zadd1_eq} RS sym; -val int_mod_add_left_eq = @{thm zmod_zadd_left_eq} RS sym; -val int_mod_add_right_eq = @{thm zmod_zadd_right_eq} RS sym; -val nat_div_add_eq = @{thm div_add1_eq} RS sym; -val int_div_add_eq = @{thm zdiv_zadd1_eq} RS sym; - -fun prepare_for_linz q fm = - let - val ps = Logic.strip_params fm - val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) - val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) - fun mk_all ((s, T), (P,n)) = - if 0 mem loose_bnos P then - (HOLogic.all_const T $ Abs (s, T, P), n) - else (incr_boundvars ~1 P, n-1) - fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; - val rhs = hs - val np = length ps - val (fm',np) = foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) - (foldr HOLogic.mk_imp c rhs, np) ps - val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT) - (OldTerm.term_frees fm' @ OldTerm.term_vars fm'); - val fm2 = foldr mk_all2 fm' vs - in (fm2, np + length vs, length rhs) end; - -(*Object quantifier to meta --*) -fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; - -(* object implication to meta---*) -fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; - - -fun linz_tac ctxt q i = ObjectLogic.atomize_prems_tac i THEN (fn st => - let - val g = List.nth (prems_of st, i - 1) - val thy = ProofContext.theory_of ctxt - (* Transform the term*) - val (t,np,nh) = prepare_for_linz q g - (* Some simpsets for dealing with mod div abs and nat*) - val mod_div_simpset = HOL_basic_ss - addsimps [refl,nat_mod_add_eq, nat_mod_add_left_eq, - nat_mod_add_right_eq, int_mod_add_eq, - int_mod_add_right_eq, int_mod_add_left_eq, - nat_div_add_eq, int_div_add_eq, - @{thm mod_self}, @{thm "zmod_self"}, - @{thm mod_by_0}, @{thm div_by_0}, - @{thm "zdiv_zero"}, @{thm "zmod_zero"}, @{thm "div_0"}, @{thm "mod_0"}, - @{thm "zdiv_1"}, @{thm "zmod_1"}, @{thm "div_1"}, @{thm "mod_1"}, - Suc_plus1] - addsimps @{thms add_ac} - addsimprocs [cancel_div_mod_proc] - val simpset0 = HOL_basic_ss - addsimps [mod_div_equality', Suc_plus1] - addsimps comp_arith - addsplits [split_zdiv, split_zmod, split_div', @{thm "split_min"}, @{thm "split_max"}] - (* Simp rules for changing (n::int) to int n *) - val simpset1 = HOL_basic_ss - addsimps [nat_number_of_def, zdvd_int] @ map (fn r => r RS sym) - [@{thm int_int_eq}, @{thm zle_int}, @{thm zless_int}, @{thm zadd_int}, @{thm zmult_int}] - addsplits [zdiff_int_split] - (*simp rules for elimination of int n*) - - val simpset2 = HOL_basic_ss - addsimps [@{thm nat_0_le}, @{thm all_nat}, @{thm ex_nat}, @{thm number_of1}, @{thm number_of2}, @{thm int_0}, @{thm int_1}] - addcongs [@{thm conj_le_cong}, @{thm imp_le_cong}] - (* simp rules for elimination of abs *) - val simpset3 = HOL_basic_ss addsplits [@{thm abs_split}] - val ct = cterm_of thy (HOLogic.mk_Trueprop t) - (* Theorem for the nat --> int transformation *) - val pre_thm = Seq.hd (EVERY - [simp_tac mod_div_simpset 1, simp_tac simpset0 1, - TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), - TRY (simp_tac simpset3 1), TRY (simp_tac cooper_ss 1)] - (trivial ct)) - fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) - (* The result of the quantifier elimination *) - val (th, tac) = case (prop_of pre_thm) of - Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ => - let val pth = linzqe_oracle (cterm_of thy (Pattern.eta_long [] t1)) - in - ((pth RS iffD2) RS pre_thm, - assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i)) - end - | _ => (pre_thm, assm_tac i) - in (rtac (((mp_step nh) o (spec_step np)) th) i - THEN tac) st - end handle Subscript => no_tac st); - -fun linz_args meth = - let val parse_flag = - Args.$$$ "no_quantify" >> (K (K false)); - in - Method.simple_args - (Scan.optional (Args.$$$ "(" |-- Scan.repeat1 parse_flag --| Args.$$$ ")") [] >> - curry (Library.foldl op |>) true) - (fn q => fn ctxt => meth ctxt q 1) - end; - -fun linz_method ctxt q i = Method.METHOD (fn facts => - Method.insert_tac facts 1 THEN linz_tac ctxt q i); - -val setup = - Method.add_method ("cooper", - linz_args linz_method, - "decision procedure for linear integer arithmetic"); - -end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/linrtac.ML --- a/src/HOL/ex/linrtac.ML Tue Feb 03 16:50:40 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -structure LinrTac = -struct - -val trace = ref false; -fun trace_msg s = if !trace then tracing s else (); - -val ferrack_ss = let val ths = [@{thm real_of_int_inject}, @{thm real_of_int_less_iff}, - @{thm real_of_int_le_iff}] - in @{simpset} delsimps ths addsimps (map (fn th => th RS sym) ths) - end; - -val binarith = - @{thms normalize_bin_simps} @ @{thms pred_bin_simps} @ @{thms succ_bin_simps} @ - @{thms add_bin_simps} @ @{thms minus_bin_simps} @ @{thms mult_bin_simps}; -val comp_arith = binarith @ simp_thms - -val zdvd_int = @{thm zdvd_int}; -val zdiff_int_split = @{thm zdiff_int_split}; -val all_nat = @{thm all_nat}; -val ex_nat = @{thm ex_nat}; -val number_of1 = @{thm number_of1}; -val number_of2 = @{thm number_of2}; -val split_zdiv = @{thm split_zdiv}; -val split_zmod = @{thm split_zmod}; -val mod_div_equality' = @{thm mod_div_equality'}; -val split_div' = @{thm split_div'}; -val Suc_plus1 = @{thm Suc_plus1}; -val imp_le_cong = @{thm imp_le_cong}; -val conj_le_cong = @{thm conj_le_cong}; -val nat_mod_add_eq = @{thm mod_add1_eq} RS sym; -val nat_mod_add_left_eq = @{thm mod_add_left_eq} RS sym; -val nat_mod_add_right_eq = @{thm mod_add_right_eq} RS sym; -val int_mod_add_eq = @{thm zmod_zadd1_eq} RS sym; -val int_mod_add_left_eq = @{thm zmod_zadd_left_eq} RS sym; -val int_mod_add_right_eq = @{thm zmod_zadd_right_eq} RS sym; -val nat_div_add_eq = @{thm div_add1_eq} RS sym; -val int_div_add_eq = @{thm zdiv_zadd1_eq} RS sym; -val ZDIVISION_BY_ZERO_MOD = @{thm DIVISION_BY_ZERO} RS conjunct2; -val ZDIVISION_BY_ZERO_DIV = @{thm DIVISION_BY_ZERO} RS conjunct1; - -fun prepare_for_linr sg q fm = - let - val ps = Logic.strip_params fm - val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) - val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) - fun mk_all ((s, T), (P,n)) = - if 0 mem loose_bnos P then - (HOLogic.all_const T $ Abs (s, T, P), n) - else (incr_boundvars ~1 P, n-1) - fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; - val rhs = hs -(* val (rhs,irhs) = List.partition (relevant (rev ps)) hs *) - val np = length ps - val (fm',np) = foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) - (foldr HOLogic.mk_imp c rhs, np) ps - val (vs, _) = List.partition (fn t => q orelse (type_of t) = HOLogic.natT) - (OldTerm.term_frees fm' @ OldTerm.term_vars fm'); - val fm2 = foldr mk_all2 fm' vs - in (fm2, np + length vs, length rhs) end; - -(*Object quantifier to meta --*) -fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; - -(* object implication to meta---*) -fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; - - -fun linr_tac ctxt q i = - (ObjectLogic.atomize_prems_tac i) - THEN (REPEAT_DETERM (split_tac [@{thm split_min}, @{thm split_max}, @{thm abs_split}] i)) - THEN (fn st => - let - val g = List.nth (prems_of st, i - 1) - val thy = ProofContext.theory_of ctxt - (* Transform the term*) - val (t,np,nh) = prepare_for_linr thy q g - (* Some simpsets for dealing with mod div abs and nat*) - val simpset0 = Simplifier.theory_context thy HOL_basic_ss addsimps comp_arith - val ct = cterm_of thy (HOLogic.mk_Trueprop t) - (* Theorem for the nat --> int transformation *) - val pre_thm = Seq.hd (EVERY - [simp_tac simpset0 1, - TRY (simp_tac (Simplifier.theory_context thy ferrack_ss) 1)] - (trivial ct)) - fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) - (* The result of the quantifier elimination *) - val (th, tac) = case (prop_of pre_thm) of - Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ => - let val pth = linr_oracle (cterm_of thy (Pattern.eta_long [] t1)) - in - (trace_msg ("calling procedure with term:\n" ^ - Syntax.string_of_term ctxt t1); - ((pth RS iffD2) RS pre_thm, - assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))) - end - | _ => (pre_thm, assm_tac i) - in (rtac (((mp_step nh) o (spec_step np)) th) i - THEN tac) st - end handle Subscript => no_tac st); - -fun linr_meth src = - Method.syntax (Args.mode "no_quantify") src - #> (fn (q, ctxt) => Method.SIMPLE_METHOD' (linr_tac ctxt (not q))); - -val setup = - Method.add_method ("rferrack", linr_meth, - "decision procedure for linear real arithmetic"); - -end diff -r 23bf900a21db -r 1b80ebe713a4 src/HOL/ex/mirtac.ML --- a/src/HOL/ex/mirtac.ML Tue Feb 03 16:50:40 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -(* Title: HOL/ex/mirtac.ML - Author: Amine Chaieb, TU Muenchen -*) - -structure MirTac = -struct - -val trace = ref false; -fun trace_msg s = if !trace then tracing s else (); - -val mir_ss = -let val ths = map thm ["real_of_int_inject", "real_of_int_less_iff", "real_of_int_le_iff"] -in @{simpset} delsimps ths addsimps (map (fn th => th RS sym) ths) -end; - -val nT = HOLogic.natT; - val nat_arith = map thm ["add_nat_number_of", "diff_nat_number_of", - "mult_nat_number_of", "eq_nat_number_of", "less_nat_number_of"]; - - val comp_arith = (map thm ["Let_def", "if_False", "if_True", "add_0", - "add_Suc", "add_number_of_left", "mult_number_of_left", - "Suc_eq_add_numeral_1"])@ - (map (fn s => thm s RS sym) ["numeral_1_eq_1", "numeral_0_eq_0"]) - @ @{thms arith_simps} @ nat_arith @ @{thms rel_simps} - val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"}, - @{thm "real_of_nat_number_of"}, - @{thm "real_of_nat_Suc"}, @{thm "real_of_nat_one"}, @{thm "real_of_one"}, - @{thm "real_of_int_zero"}, @{thm "real_of_nat_zero"}, - @{thm "Ring_and_Field.divide_zero"}, - @{thm "divide_divide_eq_left"}, @{thm "times_divide_eq_right"}, - @{thm "times_divide_eq_left"}, @{thm "divide_divide_eq_right"}, - @{thm "diff_def"}, @{thm "minus_divide_left"}] -val comp_ths = ths @ comp_arith @ simp_thms - - -val zdvd_int = @{thm "zdvd_int"}; -val zdiff_int_split = @{thm "zdiff_int_split"}; -val all_nat = @{thm "all_nat"}; -val ex_nat = @{thm "ex_nat"}; -val number_of1 = @{thm "number_of1"}; -val number_of2 = @{thm "number_of2"}; -val split_zdiv = @{thm "split_zdiv"}; -val split_zmod = @{thm "split_zmod"}; -val mod_div_equality' = @{thm "mod_div_equality'"}; -val split_div' = @{thm "split_div'"}; -val Suc_plus1 = @{thm "Suc_plus1"}; -val imp_le_cong = @{thm "imp_le_cong"}; -val conj_le_cong = @{thm "conj_le_cong"}; -val nat_mod_add_eq = @{thm "mod_add1_eq"} RS sym; -val nat_mod_add_left_eq = @{thm "mod_add_left_eq"} RS sym; -val nat_mod_add_right_eq = @{thm "mod_add_right_eq"} RS sym; -val int_mod_add_eq = @{thm "zmod_zadd1_eq"} RS sym; -val int_mod_add_left_eq = @{thm "zmod_zadd_left_eq"} RS sym; -val int_mod_add_right_eq = @{thm "zmod_zadd_right_eq"} RS sym; -val nat_div_add_eq = @{thm "div_add1_eq"} RS sym; -val int_div_add_eq = @{thm "zdiv_zadd1_eq"} RS sym; -val ZDIVISION_BY_ZERO_MOD = @{thm "DIVISION_BY_ZERO"} RS conjunct2; -val ZDIVISION_BY_ZERO_DIV = @{thm "DIVISION_BY_ZERO"} RS conjunct1; - -fun prepare_for_mir thy q fm = - let - val ps = Logic.strip_params fm - val hs = map HOLogic.dest_Trueprop (Logic.strip_assums_hyp fm) - val c = HOLogic.dest_Trueprop (Logic.strip_assums_concl fm) - fun mk_all ((s, T), (P,n)) = - if 0 mem loose_bnos P then - (HOLogic.all_const T $ Abs (s, T, P), n) - else (incr_boundvars ~1 P, n-1) - fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t; - val rhs = hs -(* val (rhs,irhs) = List.partition (relevant (rev ps)) hs *) - val np = length ps - val (fm',np) = foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n))) - (foldr HOLogic.mk_imp c rhs, np) ps - val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT) - (OldTerm.term_frees fm' @ OldTerm.term_vars fm'); - val fm2 = foldr mk_all2 fm' vs - in (fm2, np + length vs, length rhs) end; - -(*Object quantifier to meta --*) -fun spec_step n th = if (n=0) then th else (spec_step (n-1) th) RS spec ; - -(* object implication to meta---*) -fun mp_step n th = if (n=0) then th else (mp_step (n-1) th) RS mp; - - -fun mir_tac ctxt q i = - (ObjectLogic.atomize_prems_tac i) - THEN (simp_tac (HOL_basic_ss addsimps [@{thm "abs_ge_zero"}] addsimps simp_thms) i) - THEN (REPEAT_DETERM (split_tac [@{thm "split_min"}, @{thm "split_max"},@{thm "abs_split"}] i)) - THEN (fn st => - let - val g = List.nth (prems_of st, i - 1) - val thy = ProofContext.theory_of ctxt - (* Transform the term*) - val (t,np,nh) = prepare_for_mir thy q g - (* Some simpsets for dealing with mod div abs and nat*) - val mod_div_simpset = HOL_basic_ss - addsimps [refl,nat_mod_add_eq, - @{thm "mod_self"}, @{thm "zmod_self"}, - @{thm "zdiv_zero"},@{thm "zmod_zero"},@{thm "div_0"}, @{thm "mod_0"}, - @{thm "zdiv_1"}, @{thm "zmod_1"}, @{thm "div_1"}, @{thm "mod_1"}, - @{thm "Suc_plus1"}] - addsimps @{thms add_ac} - addsimprocs [cancel_div_mod_proc] - val simpset0 = HOL_basic_ss - addsimps [mod_div_equality', Suc_plus1] - addsimps comp_ths - addsplits [@{thm "split_zdiv"}, @{thm "split_zmod"}, @{thm "split_div'"}, @{thm "split_min"}, @{thm "split_max"}] - (* Simp rules for changing (n::int) to int n *) - val simpset1 = HOL_basic_ss - addsimps [@{thm "nat_number_of_def"}, @{thm "zdvd_int"}] @ map (fn r => r RS sym) - [@{thm "int_int_eq"}, @{thm "zle_int"}, @{thm "zless_int"}, @{thm "zadd_int"}, - @{thm "zmult_int"}] - addsplits [@{thm "zdiff_int_split"}] - (*simp rules for elimination of int n*) - - val simpset2 = HOL_basic_ss - addsimps [@{thm "nat_0_le"}, @{thm "all_nat"}, @{thm "ex_nat"}, @{thm "number_of1"}, - @{thm "number_of2"}, @{thm "int_0"}, @{thm "int_1"}] - addcongs [@{thm "conj_le_cong"}, @{thm "imp_le_cong"}] - (* simp rules for elimination of abs *) - val ct = cterm_of thy (HOLogic.mk_Trueprop t) - (* Theorem for the nat --> int transformation *) - val pre_thm = Seq.hd (EVERY - [simp_tac mod_div_simpset 1, simp_tac simpset0 1, - TRY (simp_tac simpset1 1), TRY (simp_tac simpset2 1), TRY (simp_tac mir_ss 1)] - (trivial ct)) - fun assm_tac i = REPEAT_DETERM_N nh (assume_tac i) - (* The result of the quantifier elimination *) - val (th, tac) = case (prop_of pre_thm) of - Const ("==>", _) $ (Const ("Trueprop", _) $ t1) $ _ => - let val pth = - (* If quick_and_dirty then run without proof generation as oracle*) - if !quick_and_dirty - then mirfr_oracle (false, cterm_of thy (Pattern.eta_long [] t1)) - else mirfr_oracle (true, cterm_of thy (Pattern.eta_long [] t1)) - in - (trace_msg ("calling procedure with term:\n" ^ - Syntax.string_of_term ctxt t1); - ((pth RS iffD2) RS pre_thm, - assm_tac (i + 1) THEN (if q then I else TRY) (rtac TrueI i))) - end - | _ => (pre_thm, assm_tac i) - in (rtac (((mp_step nh) o (spec_step np)) th) i - THEN tac) st - end handle Subscript => no_tac st); - -fun mir_args meth = - let val parse_flag = - Args.$$$ "no_quantify" >> (K (K false)); - in - Method.simple_args - (Scan.optional (Args.$$$ "(" |-- Scan.repeat1 parse_flag --| Args.$$$ ")") [] >> - curry (Library.foldl op |>) true) - (fn q => fn ctxt => meth ctxt q 1) - end; - -fun mir_method ctxt q i = Method.METHOD (fn facts => - Method.insert_tac facts 1 THEN mir_tac ctxt q i); - -val setup = - Method.add_method ("mir", - mir_args mir_method, - "decision procedure for MIR arithmetic"); - - -end