Quelle MIR.thy
Sprache: Isabelle
|
|
(* Title: HOL/Decision_Procs/MIR.thy
Author: Amine Chaieb
*)
theory MIR
imports Complex_Main Dense_Linear_Order DP_Library
"HOL-Library.Code_Target_Numeral" "HOL-Library.Old_Recdef"
begin
section ‹Prelude›
abbreviation (input) UNION :: "'a set → ('a → 'b set) → 'b set"
where "UNION A f ≡ ∪ (f ` A)" ― ‹legacy›
section ‹Quantifier elimination for ‹ℝ (0, 1, +, floor, <)\››
declare of_int_floor_cancel [simp del]
lemma myle:
fixes a b :: "'a::{ordered_ab_group_add}"
shows "(a ≤ b) = (0 ≤ b - a)"
by (metis add_0_left add_le_cancel_right diff_add_cancel)
lemma myless:
fixes a b :: "'a::{ordered_ab_group_add}"
shows "(a < b) = (0 < b - a)"
by (metis le_iff_diff_le_0 less_le_not_le myle)
(* Periodicity of dvd *)
lemmas dvd_period = zdvd_period
(* The Divisibility relation between reals *)
definition rdvd:: "real → real → bool" (infixl ‹rdvd› 50)
where "x rdvd y ⟷ (∃k::int. y = x * real_of_int k)"
lemma int_rdvd_real:
"real_of_int (i::int) rdvd x = (i dvd ⌊x⌋ ∧ real_of_int ⌊x⌋ = x)" (is "?l = ?r")
proof
assume "?l"
hence th: "∃ k. x=real_of_int (i*k)" by (simp add: rdvd_def)
hence th': "real_of_int ⌊x⌋ = x" by (auto simp del: of_int_mult)
with th have "∃ k. real_of_int ⌊x⌋ = real_of_int (i*k)" by simp
hence "∃k. ⌊x⌋ = i*k" by presburger
thus ?r using th' by (simp add: dvd_def)
next
assume "?r" hence "(i::int) dvd ⌊x::real⌋" ..
hence "∃k. real_of_int ⌊x⌋ = real_of_int (i*k)"
by (metis (no_types) dvd_def)
thus ?l using ‹?r› by (simp add: rdvd_def)
qed
lemma int_rdvd_iff: "(real_of_int (i::int) rdvd real_of_int t) = (i dvd t)"
by (auto simp add: rdvd_def dvd_def) (rule_tac x="k" in exI, simp only: of_int_mult[symmetric])
lemma rdvd_abs1: "(∣real_of_int d∣ rdvd t) = (real_of_int (d ::int) rdvd t)"
proof
assume d: "real_of_int d rdvd t"
from d int_rdvd_real have d2: "d dvd ⌊t⌋" and ti: "real_of_int ⌊t⌋ = t"
by auto
from iffD2[OF abs_dvd_iff] d2 have "∣d∣ dvd ⌊t⌋" by blast
with ti int_rdvd_real[symmetric] have "real_of_int ∣d∣ rdvd t" by blast
thus "∣real_of_int d∣ rdvd t" by simp
next
assume "∣real_of_int d∣ rdvd t" hence "real_of_int ∣d∣ rdvd t" by simp
with int_rdvd_real[where i="∣d∣" and x="t"]
have d2: "∣d∣ dvd ⌊t⌋" and ti: "real_of_int ⌊t⌋ = t"
by auto
from iffD1[OF abs_dvd_iff] d2 have "d dvd ⌊t⌋" by blast
with ti int_rdvd_real[symmetric] show "real_of_int d rdvd t" by blast
qed
lemma rdvd_minus: "(real_of_int (d::int) rdvd t) = (real_of_int d rdvd -t)"
by (metis equation_minus_iff mult_minus_right of_int_minus rdvd_def)
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_of_int (n::int) * real_of_int (k::int) rdvd x * real_of_int k) = (real_of_int n rdvd x)"
using knz by (simp add: rdvd_def)
(*********************************************************************************)
(**** SHADOW SYNTAX AND SEMANTICS ****)
(*********************************************************************************)
datatype (plugins del: size) 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
instantiation num :: size
begin
primrec size_num :: "num → nat"
where
"size_num (C c) = 1"
| "size_num (Bound n) = 1"
| "size_num (Neg a) = 1 + size_num a"
| "size_num (Add a b) = 1 + size_num a + size_num b"
| "size_num (Sub a b) = 3 + size_num a + size_num b"
| "size_num (CN n c a) = 4 + size_num a "
| "size_num (CF c a b) = 4 + size_num a + size_num b"
| "size_num (Mul c a) = 1 + size_num a"
| "size_num (Floor a) = 1 + size_num a"
instance ..
end
(* Semantics of numeral terms (num) *)
primrec Inum :: "real list → num → real"
where
"Inum bs (C c) = (real_of_int c)"
| "Inum bs (Bound n) = bs!n"
| "Inum bs (CN n c a) = (real_of_int 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_of_int c) * Inum bs a"
| "Inum bs (Floor a) = real_of_int ⌊Inum bs a⌋"
| "Inum bs (CF c a b) = real_of_int c * real_of_int ⌊Inum bs a⌋ + Inum bs b"
definition "isint t bs ≡ real_of_int ⌊Inum bs t⌋ = Inum bs t"
lemma isint_iff: "isint n bs = (real_of_int ⌊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"
assume be: "isint e bs" hence efe:"real_of_int ⌊?e⌋ = ?e" by (simp add: isint_iff)
have "real_of_int ⌊Inum bs (Mul c e)⌋ = real_of_int ⌊real_of_int (c * ⌊?e⌋)⌋"
using efe by simp
also have "… = real_of_int (c* ⌊?e⌋)" by (metis floor_of_int)
also have "… = real_of_int 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_of_int ⌊?I e⌋ = ?I e" by (simp add: isint_def)
have "real_of_int ⌊?I (Neg e)⌋ = real_of_int ⌊- (real_of_int ⌊?I e⌋)⌋"
by (simp add: th)
also have "… = - real_of_int ⌊?I e⌋" by simp
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_of_int ⌊?I e⌋ = ?I e" by (simp add: isint_def)
have "real_of_int ⌊?I (Sub (C c) e)⌋ = real_of_int ⌊real_of_int (c - ⌊?I e⌋)⌋"
by (simp add: th)
also have "… = real_of_int (c - ⌊?I e⌋)" by simp
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_of_int ⌊?a + ?b⌋ = real_of_int ⌊real_of_int ⌊?a⌋ + real_of_int ⌊?b⌋⌋"
by simp
also have "… = real_of_int ⌊?a⌋ + real_of_int ⌊?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 (plugins del: size) 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
instantiation fm :: size
begin
primrec size_fm :: "fm → nat"
where
"size_fm (Not p) = 1 + size_fm p"
| "size_fm (And p q) = 1 + size_fm p + size_fm q"
| "size_fm (Or p q) = 1 + size_fm p + size_fm q"
| "size_fm (Imp p q) = 3 + size_fm p + size_fm q"
| "size_fm (Iff p q) = 3 + 2 * (size_fm p + size_fm q)"
| "size_fm (E p) = 1 + size_fm p"
| "size_fm (A p) = 4 + size_fm p"
| "size_fm (Dvd i t) = 2"
| "size_fm (NDvd i t) = 2"
| "size_fm T = 1"
| "size_fm F = 1"
| "size_fm (Lt _) = 1"
| "size_fm (Le _) = 1"
| "size_fm (Gt _) = 1"
| "size_fm (Ge _) = 1"
| "size_fm (Eq _) = 1"
| "size_fm (NEq _) = 1"
instance ..
end
lemma size_fm_pos [simp]: "size p > 0" for p :: fm
by (induct p) 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_of_int i rdvd Inum bs b"
| "Ifm bs (NDvd i b) ⟷ ¬ (real_of_int 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)"
fun prep :: "fm → fm"
where
"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"
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
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
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
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
fun decrnum:: "num → num"
where
"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"
fun decr :: "fm → fm"
where
"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
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: decrnum)
lemma decr_qf: "bound0 p ==> qfree (decr p)"
by (induct p) simp_all
fun isatom :: "fm → bool" (* test for atomicity *)
where
"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 "∀x ∈ set xs. bound0 (f x)"
shows "bound0 (evaldjf f xs)"
using assms
by (induct xs) (auto simp add: evaldjf_def djf_def Let_def split: fm.split)
lemma evaldjf_qf:
assumes "∀x ∈ set xs. qfree (f x)"
shows "qfree (evaldjf f xs)"
using assms
by (induct xs) (auto simp add: evaldjf_def djf_def Let_def split: fm.split)
fun disjuncts :: "fm → fm list"
where
"disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
| "disjuncts F = []"
| "disjuncts p = [p]"
fun conjuncts :: "fm → fm list"
where
"conjuncts (And p q) = (conjuncts p) @ (conjuncts q)"
| "conjuncts T = []"
| "conjuncts p = [p]"
lemma conjuncts: "(∀ q∈ set (conjuncts p). Ifm bs q) = Ifm bs p"
by (induct p rule: conjuncts.induct) auto
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
definition DJ :: "(fm → fm) → fm → fm" where
"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 *)
fun bnds:: "num → nat list"
where
"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 = []"
fun lex_ns:: "nat list → nat list → bool"
where
"lex_ns [] ms = True"
| "lex_ns ns [] = False"
| "lex_ns (n#ns) (m#ms) = (n<m ∨ ((n = m) ∧ lex_ns ns ms)) "
definition lex_bnd :: "num → num → bool" where
"lex_bnd t s ≡ lex_ns (bnds t) (bnds s)"
fun maxcoeff:: "num → int"
where
"maxcoeff (C i) = ∣i∣"
| "maxcoeff (CN n c t) = max ∣c∣ (maxcoeff t)"
| "maxcoeff (CF c t s) = max ∣c∣ (maxcoeff s)"
| "maxcoeff t = 1"
lemma maxcoeff_pos: "maxcoeff t ≥ 0"
by (induct t rule: maxcoeff.induct) auto
fun numgcdh:: "num → int → int"
where
"numgcdh (C i) = (λg. gcd i g)"
| "numgcdh (CN n c t) = (λg. gcd c (numgcdh t g))"
| "numgcdh (CF c s t) = (λg. gcd c (numgcdh t g))"
| "numgcdh t = (λg. 1)"
definition numgcd :: "num → int"
where "numgcd t = numgcdh t (maxcoeff t)"
fun reducecoeffh:: "num → int → num"
where
"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 t =
(let g = numgcd t in
if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)"
fun dvdnumcoeff:: "num → int → bool"
where
"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 dvd_trans[OF gdg])
declare dvd_trans [trans add]
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)
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
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_of_int 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 assms 1 show ?case by (simp add: real_of_int_div[OF gd])
next
case (2 n c t) hence gd: "g dvd c" by simp
from assms 2 show ?case by (simp add: real_of_int_div[OF gd] algebra_simps)
next
case (3 c s t) hence gd: "g dvd c" by simp
from assms 3 show ?case by (simp add: real_of_int_div[OF gd] algebra_simps)
qed (auto simp add: numgcd_def gp)
fun ismaxcoeff:: "num → int → bool"
where
"ismaxcoeff (C i) = (λ x. ∣i∣ ≤ x)"
| "ismaxcoeff (CN n c t) = (λx. ∣c∣ ≤ x ∧ (ismaxcoeff t x))"
| "ismaxcoeff (CF c s t) = (λx. ∣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 ∣c∣ (maxcoeff t)" by simp
from ismaxcoeff_mono[OF H thh] show ?case by simp
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
qed simp_all
lemma zgcd_gt1:
"∣i∣ > 1 ∧ ∣j∣ > 1 ∨ ∣i∣ = 0 ∧ ∣j∣ > 1 ∨ ∣i∣ > 1 ∧ ∣j∣ = 0"
if "gcd i j > 1" for i j :: int
proof -
have "∣k∣ ≤ 1 ⟷ k = - 1 ∨ k = 0 ∨ k = 1" for k :: int
by auto
with that show ?thesis
by (auto simp add: not_less)
qed
lemma numgcdh0:"numgcdh t m = 0 ==> m =0"
by (induct t rule: numgcdh.induct) auto
lemma dvdnumcoeff_aux:
assumes "ismaxcoeff t m" and mp:"m ≥ 0" and "numgcdh t m > 1"
shows "dvdnumcoeff t (numgcdh t m)"
using assms
proof(induct t rule: numgcdh.induct)
case (2 n c t)
let ?g = "numgcdh t m"
from 2 have th:"gcd c ?g > 1" by simp
from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
have "(∣c∣ > 1 ∧ ?g > 1) ∨ (∣c∣ = 0 ∧ ?g > 1) ∨ (∣c∣ > 1 ∧ ?g = 0)" by simp
moreover {assume "∣c∣ > 1" and gp: "?g > 1" with 2
have th: "dvdnumcoeff t ?g" by simp
have th': "gcd c ?g dvd ?g" by simp
from dvdnumcoeff_trans[OF th' th] have ?case by simp }
moreover {assume "∣c∣ = 0 ∧ ?g > 1"
with 2 have th: "dvdnumcoeff t ?g" by simp
have th': "gcd c ?g dvd ?g" by simp
from dvdnumcoeff_trans[OF th' th] have ?case by simp
hence ?case by simp }
moreover {assume "∣c∣ > 1" and g0:"?g = 0"
from numgcdh0[OF g0] have "m=0". with 2 g0 have ?case by simp }
ultimately show ?case by blast
next
case (3 c s t)
let ?g = "numgcdh t m"
from 3 have th:"gcd c ?g > 1" by simp
from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
have "(∣c∣ > 1 ∧ ?g > 1) ∨ (∣c∣ = 0 ∧ ?g > 1) ∨ (∣c∣ > 1 ∧ ?g = 0)" by simp
moreover {assume "∣c∣ > 1" and gp: "?g > 1" with 3
have th: "dvdnumcoeff t ?g" by simp
have th': "gcd c ?g dvd ?g" by simp
from dvdnumcoeff_trans[OF th' th] have ?case by simp }
moreover {assume "∣c∣ = 0 ∧ ?g > 1"
with 3 have th: "dvdnumcoeff t ?g" by simp
have th': "gcd c ?g dvd ?g" by simp
from dvdnumcoeff_trans[OF th' th] have ?case by simp
hence ?case by simp }
moreover {assume "∣c∣ > 1" and g0:"?g = 0"
from numgcdh0[OF g0] have "m=0". with 3 g0 have ?case by simp }
ultimately show ?case by blast
qed auto
lemma dvdnumcoeff_aux2:
assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) ∧ numgcd t > 0"
using assms
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_of_int (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 numadd:: "num × num → 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)"
by (induct t s rule: numadd.induct) (simp_all add: Let_def algebra_simps add_eq_0_iff)
lemma numadd_nb [simp]: "numbound0 t ==> numbound0 s ==> numbound0 (numadd (t, s))"
by (induct t s rule: numadd.induct) (simp_all add: Let_def)
fun nummul:: "num → int → num"
where
"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
definition numneg :: "num → num"
where "numneg t ≡ nummul t (- 1)"
definition numsub :: "num → num → num"
where "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
fun split_int:: "num → num × num"
where
"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 2(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
from 2(2) have tibi: "ti = ?bi" by (simp add: Let_def split_def)
from 2(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 3(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
from 3(2) have tibi: "ti = CF c a ?bi"
by (simp add: Let_def split_def)
from 3(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 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)
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_of_int ⌊?N (Add ?tv ?ti)⌋" by simp
also have "… = real_of_int (⌊?N ?tv⌋ + ⌊?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_of_int ⌊?N (Add ?tv ?ti)⌋" by simp
also have "… = real_of_int (⌊?N ?tv⌋ + ⌊?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) }
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)
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 (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
fun nozerocoeff:: "num → bool"
where
"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 ∣c∣ (maxcoeff t) = 0" by simp+
have "max ∣c∣ (maxcoeff t) ≥ ∣c∣" by simp
with cnz have "max ∣c∣ (maxcoeff t) > 0" by arith
with 2 show ?case by simp
next
case (3 c s t)
hence cnz: "c ≠0" and mx: "max ∣c∣ (maxcoeff t) = 0" by simp+
have "max ∣c∣ (maxcoeff t) ≥ ∣c∣" by simp
with cnz have "max ∣c∣ (maxcoeff t) > 0" by arith
with 3 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
definition simp_num_pair :: "(num × int) → num × int" where
"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' = gcd 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_of_int n) (simp_num_pair (t,n))) = ((λ (t,n). Inum bs t / real_of_int n) (t,n))"
(is "?lhs = ?rhs")
proof-
let ?t' = "simpnum t"
let ?g = "numgcd ?t'"
let ?g' = "gcd 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 g1 nnz have gp0: "?g' ≠ 0" by simp
hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="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
have gpdd: "?g' dvd n" by simp
have gpdgp: "?g' dvd ?g'" by simp
from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p]
have th2:"real_of_int ?g' * ?t = Inum bs ?t'" by simp
from nnz g1 g'1 have "?lhs = ?t / real_of_int (n div ?g')" by (simp add: simp_num_pair_def Let_def)
also have "… = (real_of_int ?g' * ?t) / (real_of_int ?g' * (real_of_int (n div ?g')))" by simp
also have "… = (Inum bs ?t' / real_of_int n)"
using real_of_int_div[OF gpdd] th2 gp0 by simp
finally have "?lhs = Inum bs t / real_of_int n" by simp
then have ?thesis using nnz g1 g'1 by (simp add: simp_num_pair_def) }
ultimately have ?thesis by auto }
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' = "gcd n ?g"
{ assume nz: "n = 0" hence ?thesis using assms by (simp add: Let_def simp_num_pair_def) }
moreover
{ assume nnz: "n ≠ 0"
{assume "¬ ?g > 1" hence ?thesis using assms by (auto simp add: Let_def simp_num_pair_def) }
moreover
{assume g1:"?g>1" hence g0: "?g > 0" by simp
from g1 nnz have gp0: "?g' ≠ 0" by simp
hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
hence "?g'= 1 ∨ ?g' > 1" by arith
moreover {assume "?g'=1" hence ?thesis using assms g1 g0
by (auto simp add: Let_def simp_num_pair_def) }
moreover {assume g'1:"?g'>1"
have gpdg: "?g' dvd ?g" by simp
have gpdd: "?g' dvd n" by simp
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 div_self[OF gp0]]
have "n div ?g' >0" by simp
hence ?thesis using assms g1 g'1
by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0)}
ultimately have ?thesis by auto }
ultimately have ?thesis by blast }
ultimately show ?thesis by blast
qed
fun not:: "fm → fm"
where
"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
definition conj :: "fm → fm → fm" where
"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
definition disj :: "fm → fm → fm" where
"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
definition imp :: "fm → fm → fm" where
"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)
definition iff :: "fm → fm → fm" where
"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 iff_qf[simp]: "[qfree p ; qfree q] ==> qfree (iff p q)"
by (unfold iff_def,cases "p=q", auto)
fun check_int:: "num → bool"
where
"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_of_int ⌊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_of_int (d::int) rdvd real_of_int (c::int)*t = (real_of_int (d div g) rdvd real_of_int (c div g)*t)"
proof
assume d: "real_of_int d rdvd real_of_int c * t"
from d rdvd_def obtain k where k_def: "real_of_int c * t = real_of_int d* real_of_int (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_of_int g * real_of_int kc * t = real_of_int g * real_of_int kd * real_of_int k" by simp
hence "real_of_int kc * t = real_of_int kd * real_of_int k" using gp by simp
hence th:"real_of_int kd rdvd real_of_int 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_of_int (d div g) rdvd real_of_int (c div g) * t" by simp
next
assume d: "real_of_int (d div g) rdvd real_of_int (c div g) * t"
from gp have gnz: "g ≠ 0" by simp
thus "real_of_int d rdvd real_of_int c * t" using d rdvd_mult[OF gnz, where n="d div g" and x="real_of_int (c div g) * t"] real_of_int_div[OF gd] real_of_int_div[OF gc] by simp
qed
definition simpdvd :: "int → num → (int × num)" where
"simpdvd d t ≡
(let g = numgcd t in
if g > 1 then (let g' = gcd 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' = "gcd 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 g1 dnz have gp0: "?g' ≠ 0" by simp
hence g'p: "?g' > 0" using gcd_ge_0_int[where x="d" and y="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
have gpdd: "?g' dvd d" by simp
have gpdgp: "?g' dvd ?g'" by simp
from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p]
have th2:"real_of_int ?g' * ?t = Inum bs t" by simp
from assms g1 g0 g'1
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_of_int d rdvd (Inum bs t))"
using rdvd_reduce[OF gpdd gpdgp g'p, where t="?t", simplified div_self[OF gp0]]
th2[symmetric] by simp
finally have ?thesis by simp }
ultimately have ?thesis by auto
}
ultimately show ?thesis by blast
qed
fun 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 (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 (∣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 (∣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_of_int ?g > 0" by simp
have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
with sa have "Inum bs a < 0 = (real_of_int ?g * ?r < real_of_int ?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_of_int ?g > 0" by simp
have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
with sa have "Inum bs a ≤ 0 = (real_of_int ?g * ?r ≤ real_of_int ?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_of_int ?g > 0" by simp
have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
with sa have "Inum bs a > 0 = (real_of_int ?g * ?r > real_of_int ?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_of_int ?g > 0" by simp
have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
with sa have "Inum bs a ≥ 0 = (real_of_int ?g * ?r ≥ real_of_int ?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_of_int ?g > 0" by simp
have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
with sa have "Inum bs a = 0 = (real_of_int ?g * ?r = 0)" by simp
also have "… = (?r = 0)" using gp
by simp
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_of_int ?g > 0" by simp
have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
with sa have "Inum bs a ≠ 0 = (real_of_int ?g * ?r ≠ 0)" by simp
also have "… = (?r ≠ 0)" using gp
by simp
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 ∨ (∣i∣ = 1 ∧ check_int a) ∨ (i≠0 ∧ ((∣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: "∣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: "(∣i∣ ≠ 1) ∨ (¬ check_int a)"
{fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
by (cases "∣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 ∨ (∣i∣ = 1 ∧ check_int a) ∨ (i≠0 ∧ ((∣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: "∣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: "(∣i∣ ≠ 1) ∨ (¬ check_int a)"
{fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
by (cases "∣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 *)
definition list_conj :: "fm list → fm" where
"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)
definition CJNB :: "(fm → fm) → fm → fm" where
"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 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] simp del: partition_filter_conv)
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
fun qelim :: "fm → (fm → fm) → fm"
where
"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 ‹ℤ› Part›
text‹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 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'))"
lemma zsplit0_I:
shows "∧ n a. zsplit0 t = (n,a) ==> (Inum ((real_of_int (x::int)) #bs) (CN 0 n a) = Inum (real_of_int 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 5
by (simp add: Let_def split_def)
from abj 5 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 6
by (simp add: Let_def split_def)
from abjs[symmetric] have bluddy: "∃ x y. (x,y) = zsplit0 s" by blast
from 6 have "(∃ x y. (x,y) = zsplit0 s) ⟶ (∀xa xb. zsplit0 t = (xa, xb) ⟶ Inum (real_of_int x # bs) (CN 0 xa xb) = Inum (real_of_int x # bs) t ∧ numbound0 xb)" by blast (*FIXME*)
with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) ∧ ?N ?at" by blast
from abjs 6 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: distrib_right)
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 7
by (simp add: Let_def split_def)
from abjs[symmetric] have bluddy: "∃ x y. (x,y) = zsplit0 s" by blast
from 7 have "(∃ x y. (x,y) = zsplit0 s) ⟶ (∀xa xb. zsplit0 t = (xa, xb) ⟶ Inum (real_of_int x # bs) (CN 0 xa xb) = Inum (real_of_int x # bs) t ∧ numbound0 xb)" by blast (*FIXME*)
with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) ∧ ?N ?at" by blast
from abjs 7 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 8
by (simp add: Let_def split_def)
from abj 8 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) ∧ ?N ?at" by blast
hence "?I x (Mul i t) = (real_of_int i) * ?I x (CN 0 ?nt ?at)" by simp
also have "… = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: distrib_left)
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 9
by (simp add: Let_def split_def)
from abj 9 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_of_int ?nt)*(real_of_int x) = real_of_int (?nt * x)" by simp
have "?I x (Floor t) = ?I x (Floor (CN 0 ?nt ?at))" using th2 by simp
also have "… = real_of_int ⌊real_of_int ?nt * real_of_int x + ?I x ?at⌋" by simp
also have "… = real_of_int ⌊?I x ?at + real_of_int (?nt * x)⌋" by (simp add: ac_simps)
also have "… = real_of_int (⌊?I x ?at⌋ + (?nt * x))"
by (simp add: of_int_mult[symmetric] del: of_int_mult)
also have "… = real_of_int (?nt)*(real_of_int x) + real_of_int ⌊?I x ?at⌋" by (simp add: ac_simps)
finally have "?I x (Floor t) = ?I x (CN 0 n a)" using th by simp
with na show ?case by simp
qed
fun iszlfm :: "fm → real list → bool" (* Linearity test for fm *)
where
"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)
fun zlfm :: "fm → fm" (* Linearity transformation for fm *)
where
"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 ∣i∣ r else
if c>0 then And (Eq (Sub (Floor r) r)) (Dvd ∣i∣ (CN 0 c (Floor r)))
else And (Eq (Sub (Floor r) r)) (Dvd ∣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 ∣i∣ r else
if c>0 then Or (NEq (Sub (Floor r) r)) (NDvd ∣i∣ (CN 0 c (Floor r)))
else Or (NEq (Sub (Floor r) r)) (NDvd ∣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"
lemma split_int_less_real:
"(real_of_int (a::int) < b) = (a < ⌊b⌋ ∨ (a = ⌊b⌋ ∧ real_of_int ⌊b⌋ < b))"
proof( auto)
assume alb: "real_of_int a < b" and agb: "¬ a < ⌊b⌋"
from agb have "⌊b⌋ ≤ a" by simp
hence th: "b < real_of_int a + 1" by (simp only: floor_le_iff)
from floor_eq[OF alb th] show "a = ⌊b⌋" by simp
next
assume alb: "a < ⌊b⌋"
hence "real_of_int a < real_of_int ⌊b⌋" by simp
moreover have "real_of_int ⌊b⌋ ≤ b" by simp
ultimately show "real_of_int a < b" by arith
qed
lemma split_int_less_real':
"(real_of_int (a::int) + b < 0) = (real_of_int a - real_of_int ⌊- b⌋ < 0 ∨ (real_of_int a - real_of_int ⌊- b⌋ = 0 ∧ real_of_int ⌊- b⌋ + b < 0))"
proof-
have "(real_of_int a + b <0) = (real_of_int 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_of_int (a::int) + b > 0) = (real_of_int a + real_of_int ⌊b⌋ > 0 ∨ (real_of_int a + real_of_int ⌊b⌋ = 0 ∧ real_of_int ⌊b⌋ - b < 0))"
proof-
have th: "(real_of_int a + b >0) = (real_of_int (-a) + (-b)< 0)" by arith
show ?thesis
by (simp only:th split_int_less_real'[where a="-a" and b="-b"]) (auto simp add: algebra_simps)
qed
lemma split_int_le_real:
"(real_of_int (a::int) ≤ b) = (a ≤ ⌊b⌋ ∨ (a = ⌊b⌋ ∧ real_of_int ⌊b⌋ < b))"
proof( auto)
assume alb: "real_of_int a ≤ b" and agb: "¬ a ≤ ⌊b⌋"
from alb have "⌊real_of_int a⌋ ≤ ⌊b⌋" by (simp only: floor_mono)
hence "a ≤ ⌊b⌋" by simp with agb show "False" by simp
next
assume alb: "a ≤ ⌊b⌋"
hence "real_of_int a ≤ real_of_int ⌊b⌋" by (simp only: floor_mono)
also have "…≤ b" by simp finally show "real_of_int a ≤ b" .
qed
lemma split_int_le_real':
"(real_of_int (a::int) + b ≤ 0) = (real_of_int a - real_of_int ⌊- b⌋ ≤ 0 ∨ (real_of_int a - real_of_int ⌊- b⌋ = 0 ∧ real_of_int ⌊- b⌋ + b < 0))"
proof-
have "(real_of_int a + b ≤0) = (real_of_int 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_of_int (a::int) + b ≥ 0) = (real_of_int a + real_of_int ⌊b⌋ ≥ 0 ∨ (real_of_int a + real_of_int ⌊b⌋ = 0 ∧ real_of_int ⌊b⌋ - b < 0))"
proof-
have th: "(real_of_int a + b ≥0) = (real_of_int (-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 ,arith)
qed
lemma split_int_eq_real: "(real_of_int (a::int) = b) = ( a = ⌊b⌋ ∧ b = real_of_int ⌊b⌋)" (is "?l = ?r")
by auto
lemma split_int_eq_real': "(real_of_int (a::int) + b = 0) = ( a - ⌊- b⌋ = 0 ∧ real_of_int ⌊- b⌋ + b = 0)" (is "?l = ?r")
proof-
have "?l = (real_of_int 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_of_int i #bs) (zlfm p) = Ifm (real_of_int i# bs) p) ∧ iszlfm (zlfm p) (real_of_int (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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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,rename_tac nat a b,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_of_int (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
also have "… = (?I (?l (Lt a)))"
unfolding split_int_less_real'[where a="?c*i" and b="?N ?r"]
by (simp add: Ia cp cnz Let_def split_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_of_int (?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 ac_simps, 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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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, rename_tac nat a b, 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_of_int (?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)
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_of_int (?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 ac_simps, 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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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, rename_tac nat a b, 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_of_int (?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)
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_of_int (?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 ac_simps, 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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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, rename_tac nat a b, 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_of_int (?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)
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_of_int (?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 ac_simps, 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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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, rename_tac nat a b, 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_of_int (?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 of_int_mult[symmetric] del: 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_of_int (?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 of_int_mult[symmetric] del: 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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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, rename_tac nat a b, 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_of_int (?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 of_int_mult[symmetric] del: 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_of_int (?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 of_int_mult[symmetric] del: 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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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: "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def)
hence ?case using 11 j 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, rename_tac nat a b, 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_of_int j rdvd (real_of_int (?c * i) + (?N ?r)))"
using Ia by (simp add: Let_def split_def)
also have "… = (real_of_int ∣j∣ rdvd real_of_int (?c*i) + (?N ?r))"
by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
also have "… = (∣j∣ dvd ⌊(?N ?r) + real_of_int (?c*i)⌋ ∧
(real_of_int ⌊(?N ?r) + real_of_int (?c*i)⌋ = (real_of_int (?c*i) + (?N ?r))))"
by(simp only: int_rdvd_real[where i="∣j∣" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
also have "… = (?I (?l (Dvd j a)))" using cp cnz jnz
by (simp add: Let_def split_def int_rdvd_iff[symmetric]
del: of_int_mult) (auto simp add: ac_simps)
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_of_int j rdvd (real_of_int (?c * i) + (?N ?r)))"
using Ia by (simp add: Let_def split_def)
also have "… = (real_of_int ∣j∣ rdvd real_of_int (?c*i) + (?N ?r))"
by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
also have "… = (∣j∣ dvd ⌊(?N ?r) + real_of_int (?c*i)⌋ ∧
(real_of_int ⌊(?N ?r) + real_of_int (?c*i)⌋ = (real_of_int (?c*i) + (?N ?r))))"
by(simp only: int_rdvd_real[where i="∣j∣" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
also have "… = (?I (?l (Dvd j a)))" using cn cnz jnz
using rdvd_minus [where d="∣j∣" and t="real_of_int (?c*i + ⌊?N ?r⌋)", simplified, symmetric]
by (simp add: Let_def split_def int_rdvd_iff[symmetric]
del: of_int_mult) (auto simp add: ac_simps)
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_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
let ?N = "λ t. Inum (real_of_int 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: "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def)
hence ?case using 12 j 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, rename_tac nat a b, 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_of_int j rdvd (real_of_int (?c * i) + (?N ?r))))"
using Ia by (simp add: Let_def split_def)
also have "… = (¬ (real_of_int ∣j∣ rdvd real_of_int (?c*i) + (?N ?r)))"
by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
also have "… = (¬ (∣j∣ dvd ⌊(?N ?r) + real_of_int (?c*i)⌋ ∧
(real_of_int ⌊(?N ?r) + real_of_int (?c*i)⌋ = (real_of_int (?c*i) + (?N ?r)))))"
by(simp only: int_rdvd_real[where i="∣j∣" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
also have "… = (?I (?l (NDvd j a)))" using cp cnz jnz
by (simp add: Let_def split_def int_rdvd_iff[symmetric]
del: of_int_mult) (auto simp add: ac_simps)
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_of_int j rdvd (real_of_int (?c * i) + (?N ?r))))"
using Ia by (simp add: Let_def split_def)
also have "… = (¬ (real_of_int ∣j∣ rdvd real_of_int (?c*i) + (?N ?r)))"
by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
also have "… = (¬ (∣j∣ dvd ⌊(?N ?r) + real_of_int (?c*i)⌋ ∧
(real_of_int ⌊(?N ?r) + real_of_int (?c*i)⌋ = (real_of_int (?c*i) + (?N ?r)))))"
by(simp only: int_rdvd_real[where i="∣j∣" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
also have "… = (?I (?l (NDvd j a)))" using cn cnz jnz
using rdvd_minus [where d="∣j∣" and t="real_of_int (?c*i + ⌊?N ?r⌋)", simplified, symmetric]
by (simp add: Let_def split_def int_rdvd_iff[symmetric]
del: of_int_mult) (auto simp add: ac_simps)
finally have ?case using l jnz by blast }
ultimately show ?case by blast
qed auto
text‹plusinf : Virtual substitution of ‹+∞›
minusinf: Virtual substitution of ‹-∞›
‹δ› Compute lcm ‹d| Dvd d c*x+t ∈ p›
‹d_δ› checks if a given l divides all the ds above›
fun minusinf:: "fm → fm"
where
"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)
fun plusinf:: "fm → fm"
where
"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"
fun δ :: "fm → int"
where
"δ (And p q) = lcm (δ p) (δ q)"
| "δ (Or p q) = lcm (δ p) (δ q)"
| "δ (Dvd i (CN 0 c e)) = i"
| "δ (NDvd i (CN 0 c e)) = i"
| "δ p = 1"
fun d_δ :: "fm → int → bool"
where
"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: dvd_trans[of "i" "d" "d'"])
next
case (10 i c e) thus ?case using d
by (simp add: dvd_trans[of "i" "d" "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 1 lcm_pos_int have dp: "?d >0" by simp
have d1: "δ p dvd δ (And p q)" using 1 by simp
hence th: "d_δ p ?d"
using delta_mono 1 by (simp only: iszlfm.simps) blast
have "δ q dvd δ (And p q)" using 1 by simp
hence th': "d_δ q ?d" using delta_mono 1 by (simp only: iszlfm.simps) blast
from th th' dp show ?case by simp
next
case (2 p q)
let ?d = "δ (And p q)"
from 2 lcm_pos_int have dp: "?d >0" by simp
have "δ p dvd δ (And p q)" using 2 by simp
hence th: "d_δ p ?d" using delta_mono 2 by (simp only: iszlfm.simps) blast
have "δ q dvd δ (And p q)" using 2 by simp
hence th': "d_δ q ?d" using delta_mono 2 by (simp only: iszlfm.simps) blast
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_of_int x)#bs) (minusinf p) = Ifm ((real_of_int 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)
then have "?P f" by simp
then obtain z1 where z1_def: "∀ x < z1. ?I x (?M f) = ?I x f" by blast
with 1 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)
then have "?P f" by simp
then obtain z1 where z1_def: "∀ x < z1. ?I x (?M f) = ?I x f" by blast
with 2 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)
then have "c > 0" by simp
hence rcpos: "real_of_int c > 0" by simp
from 3 have nbe: "numbound0 e" by simp
fix y
have "∀ x < ⌊- (Inum (y#bs) e) / (real_of_int c)⌋. ?I x (?M (Eq (CN 0 c e))) = ?I x (Eq (CN 0 c e))"
proof (simp add: less_floor_iff , rule allI, rule impI)
fix x :: int
assume A: "real_of_int x + 1 ≤ - (Inum (y # bs) e / real_of_int c)"
hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
with rcpos have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
by (simp only: mult_strict_left_mono [OF th1 rcpos])
hence "real_of_int c * real_of_int x + Inum (y # bs) e ≠ 0"using rcpos by simp
thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e ≠ 0"
using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] by simp
qed
thus ?case by blast
next
case (4 c e)
then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
from 4 have nbe: "numbound0 e" by simp
fix y
have "∀ x < ⌊- (Inum (y#bs) e) / (real_of_int c)⌋. ?I x (?M (NEq (CN 0 c e))) = ?I x (NEq (CN 0 c e))"
proof (simp add: less_floor_iff , rule allI, rule impI)
fix x :: int
assume A: "real_of_int x + 1 ≤ - (Inum (y # bs) e / real_of_int c)"
hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
with rcpos have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
by (simp only: mult_strict_left_mono [OF th1 rcpos])
hence "real_of_int c * real_of_int x + Inum (y # bs) e ≠ 0"using rcpos by simp
thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e ≠ 0"
using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] by simp
qed
thus ?case by blast
next
case (5 c e)
then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
from 5 have nbe: "numbound0 e" by simp
fix y
have "∀ x < ⌊- (Inum (y#bs) e) / (real_of_int c)⌋. ?I x (?M (Lt (CN 0 c e))) = ?I x (Lt (CN 0 c e))"
proof (simp add: less_floor_iff , rule allI, rule impI)
fix x :: int
assume A: "real_of_int x + 1 ≤ - (Inum (y # bs) e / real_of_int c)"
hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
with rcpos have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
by (simp only: mult_strict_left_mono [OF th1 rcpos])
thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e < 0"
using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
qed
thus ?case by blast
next
case (6 c e)
then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
from 6 have nbe: "numbound0 e" by simp
fix y
have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Le (CN 0 c e))) = ?I x (Le (CN 0 c e))"
proof (simp add: less_floor_iff , rule allI, rule impI)
fix x :: int
assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
with rcpos have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
by (simp only: mult_strict_left_mono [OF th1 rcpos])
thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<le> 0"
using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
qed
thus ?case by blast
next
case (7 c e)
then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
from 7 have nbe: "numbound0 e" by simp
fix y
have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Gt (CN 0 c e))) = ?I x (Gt (CN 0 c e))"
proof (simp add: less_floor_iff , rule allI, rule impI)
fix x :: int
assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
with rcpos have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
by (simp only: mult_strict_left_mono [OF th1 rcpos])
thus "\<not> (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e>0)"
using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
qed
thus ?case by blast
next
case (8 c e)
then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
from 8 have nbe: "numbound0 e" by simp
fix y
have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Ge (CN 0 c e))) = ?I x (Ge (CN 0 c e))"
proof (simp add: less_floor_iff , rule allI, rule impI)
fix x :: int
assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
with rcpos have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
by (simp only: mult_strict_left_mono [OF th1 rcpos])
thus "\<not> real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<ge> 0"
using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
qed
thus ?case by blast
qed simp_all
lemma minusinf_repeats:
assumes d: "d_\<delta> p d" and linp: "iszlfm p (a # bs)"
shows "Ifm ((real_of_int(x - k*d))#bs) (minusinf p) = Ifm (real_of_int 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 "\<exists> 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_of_int x - real_of_int k * real_of_int d" and b'="real_of_int x"] right_diff_distrib, rule iffI)
assume
"real_of_int i rdvd real_of_int c * real_of_int x - real_of_int c * (real_of_int k * real_of_int d) + Inum (real_of_int x # bs) e"
(is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt")
hence "\<exists> (l::int). ?rt = ?ri * (real_of_int l)" by (simp add: rdvd_def)
hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real_of_int l)+?rc*(?rk * (real_of_int i) * (real_of_int di))"
by (simp add: algebra_simps di_def)
hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real_of_int (l + c*k*di))"
by (simp add: algebra_simps)
hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri* (real_of_int l)" by blast
thus "real_of_int i rdvd real_of_int c * real_of_int x + Inum (real_of_int x # bs) e" using rdvd_def by simp
next
assume
"real_of_int i rdvd real_of_int c * real_of_int x + Inum (real_of_int x # bs) e" (is "?ri rdvd ?rc*?rx+?e")
hence "\<exists> (l::int). ?rc*?rx+?e = ?ri * (real_of_int l)" by (simp add: rdvd_def)
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int l) - real_of_int c * (real_of_int k * real_of_int d)" by simp
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int l) - real_of_int c * (real_of_int k * real_of_int i * real_of_int di)" by (simp add: di_def)
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int (l - c*k*di))" by (simp add: algebra_simps)
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int l)"
by blast
thus "real_of_int i rdvd real_of_int c * real_of_int x - real_of_int c * (real_of_int k * real_of_int d) + Inum (real_of_int 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 "\<exists> 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_of_int x - real_of_int k * real_of_int d" and b'="real_of_int x"] right_diff_distrib, rule iffI)
assume
"real_of_int i rdvd real_of_int c * real_of_int x - real_of_int c * (real_of_int k * real_of_int d) + Inum (real_of_int x # bs) e"
(is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt")
hence "\<exists> (l::int). ?rt = ?ri * (real_of_int l)" by (simp add: rdvd_def)
hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real_of_int l)+?rc*(?rk * (real_of_int i) * (real_of_int di))"
by (simp add: algebra_simps di_def)
hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real_of_int (l + c*k*di))"
by (simp add: algebra_simps)
hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri* (real_of_int l)" by blast
thus "real_of_int i rdvd real_of_int c * real_of_int x + Inum (real_of_int x # bs) e" using rdvd_def by simp
next
assume
"real_of_int i rdvd real_of_int c * real_of_int x + Inum (real_of_int x # bs) e" (is "?ri rdvd ?rc*?rx+?e")
hence "\<exists> (l::int). ?rc*?rx+?e = ?ri * (real_of_int l)"
by (simp add: rdvd_def)
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int l) - real_of_int c * (real_of_int k * real_of_int d)"
by simp
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int l) - real_of_int c * (real_of_int k * real_of_int i * real_of_int di)"
by (simp add: di_def)
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int (l - c*k*di))"
by (simp add: algebra_simps)
hence "\<exists> (l::int). ?rc*?rx - real_of_int c * (real_of_int k * real_of_int d) +?e = ?ri * (real_of_int l)"
by blast
thus "real_of_int i rdvd real_of_int c * real_of_int x - real_of_int c * (real_of_int k * real_of_int d) + Inum (real_of_int x # bs) e"
using rdvd_def by simp
qed
qed (auto simp add: numbound0_I[where bs="bs" and b="real_of_int(x - k*d)" and b'="real_of_int x"] simp del: of_int_mult of_int_diff)
lemma minusinf_ex:
assumes lin: "iszlfm p (real_of_int (a::int) #bs)"
and exmi: "\<exists> (x::int). Ifm (real_of_int x#bs) (minusinf p)" (is "\<exists> x. ?P1 x")
shows "\<exists> (x::int). Ifm (real_of_int x#bs) p" (is "\<exists> x. ?P x")
proof-
let ?d = "\<delta> p"
from \<delta> [OF lin] have dpos: "?d >0" by simp
from \<delta> [OF lin] have alld: "d_\<delta> p ?d" by simp
from minusinf_repeats[OF alld lin] have th1:"\<forall> x k. ?P1 x = ?P1 (x - (k * ?d))" by simp
from minusinf_inf[OF lin] have th2:"\<exists> z. \<forall> x. x<z \<longrightarrow> (?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_of_int (a::int) #bs)"
shows "(\<exists> (x::int). Ifm (real_of_int x#bs) (minusinf p)) =
(\<exists> (x::int)\<in> {1..\<delta> p}. Ifm (real_of_int x#bs) (minusinf p))"
(is "(\<exists> x. ?P x) = _")
proof-
let ?d = "\<delta> p"
from \<delta> [OF lin] have dpos: "?d >0" by simp
from \<delta> [OF lin] have alld: "d_\<delta> p ?d" by simp
from minusinf_repeats[OF alld lin] have th1:"\<forall> 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 \<Longrightarrow> is_unit x \<longleftrightarrow> x = 1" for x :: int
by simp
fun a_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> fm" (* adjusts the coefficients of a formula *)
where
"a_\<beta> (And p q) = (\<lambda> k. And (a_\<beta> p k) (a_\<beta> q k))"
| "a_\<beta> (Or p q) = (\<lambda> k. Or (a_\<beta> p k) (a_\<beta> q k))"
| "a_\<beta> (Eq (CN 0 c e)) = (\<lambda> k. Eq (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (NEq (CN 0 c e)) = (\<lambda> k. NEq (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (Lt (CN 0 c e)) = (\<lambda> k. Lt (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (Le (CN 0 c e)) = (\<lambda> k. Le (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (Gt (CN 0 c e)) = (\<lambda> k. Gt (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (Ge (CN 0 c e)) = (\<lambda> k. Ge (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (Dvd i (CN 0 c e)) =(\<lambda> k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> (NDvd i (CN 0 c e))=(\<lambda> k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))"
| "a_\<beta> p = (\<lambda> k. p)"
fun d_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> bool" (* tests if all coeffs c of c divide a given l*)
where
"d_\<beta> (And p q) = (\<lambda> k. (d_\<beta> p k) \<and> (d_\<beta> q k))"
| "d_\<beta> (Or p q) = (\<lambda> k. (d_\<beta> p k) \<and> (d_\<beta> q k))"
| "d_\<beta> (Eq (CN 0 c e)) = (\<lambda> k. c dvd k)"
| "d_\<beta> (NEq (CN 0 c e)) = (\<lambda> k. c dvd k)"
| "d_\<beta> (Lt (CN 0 c e)) = (\<lambda> k. c dvd k)"
| "d_\<beta> (Le (CN 0 c e)) = (\<lambda> k. c dvd k)"
| "d_\<beta> (Gt (CN 0 c e)) = (\<lambda> k. c dvd k)"
| "d_\<beta> (Ge (CN 0 c e)) = (\<lambda> k. c dvd k)"
| "d_\<beta> (Dvd i (CN 0 c e)) =(\<lambda> k. c dvd k)"
| "d_\<beta> (NDvd i (CN 0 c e))=(\<lambda> k. c dvd k)"
| "d_\<beta> p = (\<lambda> k. True)"
fun \<zeta> :: "fm \<Rightarrow> int" (* computes the lcm of all coefficients of x*)
where
"\<zeta> (And p q) = lcm (\<zeta> p) (\<zeta> q)"
| "\<zeta> (Or p q) = lcm (\<zeta> p) (\<zeta> q)"
| "\<zeta> (Eq (CN 0 c e)) = c"
| "\<zeta> (NEq (CN 0 c e)) = c"
| "\<zeta> (Lt (CN 0 c e)) = c"
| "\<zeta> (Le (CN 0 c e)) = c"
| "\<zeta> (Gt (CN 0 c e)) = c"
| "\<zeta> (Ge (CN 0 c e)) = c"
| "\<zeta> (Dvd i (CN 0 c e)) = c"
| "\<zeta> (NDvd i (CN 0 c e))= c"
| "\<zeta> p = 1"
fun \<beta> :: "fm \<Rightarrow> num list"
where
"\<beta> (And p q) = (\<beta> p @ \<beta> q)"
| "\<beta> (Or p q) = (\<beta> p @ \<beta> q)"
| "\<beta> (Eq (CN 0 c e)) = [Sub (C (- 1)) e]"
| "\<beta> (NEq (CN 0 c e)) = [Neg e]"
| "\<beta> (Lt (CN 0 c e)) = []"
| "\<beta> (Le (CN 0 c e)) = []"
| "\<beta> (Gt (CN 0 c e)) = [Neg e]"
| "\<beta> (Ge (CN 0 c e)) = [Sub (C (- 1)) e]"
| "\<beta> p = []"
fun \<alpha> :: "fm \<Rightarrow> num list"
where
"\<alpha> (And p q) = (\<alpha> p @ \<alpha> q)"
| "\<alpha> (Or p q) = (\<alpha> p @ \<alpha> q)"
| "\<alpha> (Eq (CN 0 c e)) = [Add (C (- 1)) e]"
| "\<alpha> (NEq (CN 0 c e)) = [e]"
| "\<alpha> (Lt (CN 0 c e)) = [e]"
| "\<alpha> (Le (CN 0 c e)) = [Add (C (- 1)) e]"
| "\<alpha> (Gt (CN 0 c e)) = []"
| "\<alpha> (Ge (CN 0 c e)) = []"
| "\<alpha> p = []"
fun mirror :: "fm \<Rightarrow> fm"
where
"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_\<alpha>_\<beta>:
assumes lp: "iszlfm p (a#bs)"
shows "(Inum (real_of_int (i::int)#bs)) ` set (\<alpha> p) = (Inum (real_of_int i#bs)) ` set (\<beta> (mirror p))"
using lp by (induct p rule: mirror.induct) auto
lemma mirror:
assumes lp: "iszlfm p (a#bs)"
shows "Ifm (real_of_int (x::int)#bs) (mirror p) = Ifm (real_of_int (- x)#bs) p"
using lp
proof(induct p rule: iszlfm.induct)
case (9 j c e)
have th: "(real_of_int j rdvd real_of_int c * real_of_int x - Inum (real_of_int x # bs) e) =
(real_of_int j rdvd - (real_of_int c * real_of_int x - Inum (real_of_int x # bs) e))"
by (simp only: rdvd_minus[symmetric])
from 9 th show ?case
by (simp add: algebra_simps
numbound0_I[where bs="bs" and b'="real_of_int x" and b="- real_of_int x"])
next
case (10 j c e)
have th: "(real_of_int j rdvd real_of_int c * real_of_int x - Inum (real_of_int x # bs) e) =
(real_of_int j rdvd - (real_of_int c * real_of_int x - Inum (real_of_int x # bs) e))"
by (simp only: rdvd_minus[symmetric])
from 10 th show ?case
by (simp add: algebra_simps
numbound0_I[where bs="bs" and b'="real_of_int x" and b="- real_of_int x"])
qed (auto simp add: numbound0_I[where bs="bs" and b="real_of_int x" and b'="- real_of_int x"])
lemma mirror_l: "iszlfm p (a#bs) \<Longrightarrow> iszlfm (mirror p) (a#bs)"
by (induct p rule: mirror.induct) (auto simp add: isint_neg)
lemma mirror_d_\<beta>: "iszlfm p (a#bs) \<and> d_\<beta> p 1
\<Longrightarrow> iszlfm (mirror p) (a#bs) \<and> d_\<beta> (mirror p) 1"
by (induct p rule: mirror.induct) (auto simp add: isint_neg)
lemma mirror_\<delta>: "iszlfm p (a#bs) \<Longrightarrow> \<delta> (mirror p) = \<delta> p"
by (induct p rule: mirror.induct) auto
lemma mirror_ex:
assumes lp: "iszlfm p (real_of_int (i::int)#bs)"
shows "(\<exists> (x::int). Ifm (real_of_int x#bs) (mirror p)) = (\<exists> (x::int). Ifm (real_of_int x#bs) p)"
(is "(\<exists> x. ?I x ?mp) = (\<exists> x. ?I x p)")
proof(auto)
fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast
thus "\<exists> 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 "\<exists> x. ?I x ?mp" by blast
qed
lemma \<beta>_numbound0: assumes lp: "iszlfm p bs"
shows "\<forall> b\<in> set (\<beta> p). numbound0 b"
using lp by (induct p rule: \<beta>.induct,auto)
lemma d_\<beta>_mono:
assumes linp: "iszlfm p (a #bs)"
and dr: "d_\<beta> p l"
and d: "l dvd l'"
shows "d_\<beta> p l'"
using dr linp dvd_trans[of _ "l" "l'", simplified d]
by (induct p rule: iszlfm.induct) simp_all
lemma \<alpha>_l: assumes lp: "iszlfm p (a#bs)"
shows "\<forall> b\<in> set (\<alpha> p). numbound0 b \<and> isint b (a#bs)"
using lp
by(induct p rule: \<alpha>.induct, auto simp add: isint_add isint_c)
lemma \<zeta>:
assumes linp: "iszlfm p (a #bs)"
shows "\<zeta> p > 0 \<and> d_\<beta> p (\<zeta> p)"
using linp
proof(induct p rule: iszlfm.induct)
case (1 p q)
then have dl1: "\<zeta> p dvd lcm (\<zeta> p) (\<zeta> q)" by simp
from 1 have dl2: "\<zeta> q dvd lcm (\<zeta> p) (\<zeta> q)" by simp
from 1 d_\<beta>_mono[where p = "p" and l="\<zeta> p" and l'="lcm (\<zeta> p) (\<zeta> q)"]
d_\<beta>_mono[where p = "q" and l="\<zeta> q" and l'="lcm (\<zeta> p) (\<zeta> q)"]
dl1 dl2 show ?case by (auto simp add: lcm_pos_int)
next
case (2 p q)
then have dl1: "\<zeta> p dvd lcm (\<zeta> p) (\<zeta> q)" by simp
from 2 have dl2: "\<zeta> q dvd lcm (\<zeta> p) (\<zeta> q)" by simp
from 2 d_\<beta>_mono[where p = "p" and l="\<zeta> p" and l'="lcm (\<zeta> p) (\<zeta> q)"]
d_\<beta>_mono[where p = "q" and l="\<zeta> q" and l'="lcm (\<zeta> p) (\<zeta> q)"]
dl1 dl2 show ?case by (auto simp add: lcm_pos_int)
qed (auto simp add: lcm_pos_int)
lemma a_\<beta>: assumes linp: "iszlfm p (a #bs)" and d: "d_\<beta> p l" and lp: "l > 0"
shows "iszlfm (a_\<beta> p l) (a #bs) \<and> d_\<beta> (a_\<beta> p l) 1 \<and> (Ifm (real_of_int (l * x) #bs) (a_\<beta> p l) = Ifm ((real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e < (0::real)) =
(real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e < 0)"
by simp
also have "\<dots> = (real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e) < (real_of_int (l div c)) * 0)" by (simp add: algebra_simps)
also have "\<dots> = (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e < 0)"
using mult_less_0_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e"] ldcp by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e \<le> (0::real)) =
(real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e \<le> 0)"
by simp
also have "\<dots> = (real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e) \<le> (real_of_int (l div c)) * 0)" by (simp add: algebra_simps)
also have "\<dots> = (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<le> 0)"
using mult_le_0_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e"] ldcp by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e > (0::real)) =
(real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e > 0)"
by simp
also have "\<dots> = (real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e) > (real_of_int (l div c)) * 0)" by (simp add: algebra_simps)
also have "\<dots> = (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e > 0)"
using zero_less_mult_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e"] ldcp by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e \<ge> (0::real)) =
(real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e \<ge> 0)"
by simp
also have "\<dots> = (real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e) \<ge> (real_of_int (l div c)) * 0)" by (simp add: algebra_simps)
also have "\<dots> = (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<ge> 0)"
using zero_le_mult_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e"] ldcp by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e = (0::real)) =
(real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e = 0)"
by simp
also have "\<dots> = (real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e) = (real_of_int (l div c)) * 0)" by (simp add: algebra_simps)
also have "\<dots> = (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e = 0)"
using mult_eq_0_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e"] ldcp by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e \<noteq> (0::real)) =
(real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e \<noteq> 0)"
by simp
also have "\<dots> = (real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e) \<noteq> (real_of_int (l div c)) * 0)" by (simp add: algebra_simps)
also have "\<dots> = (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<noteq> 0)"
using zero_le_mult_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e"] ldcp by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(\<exists> (k::int). real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e = (real_of_int (l div c) * real_of_int j) * real_of_int k) = (\<exists> (k::int). real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e = (real_of_int (l div c) * real_of_int j) * real_of_int k)" by simp
also have "\<dots> = (\<exists> (k::int). real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e - real_of_int j * real_of_int k) = real_of_int (l div c)*0)" by (simp add: algebra_simps)
also fix k have "\<dots> = (\<exists> (k::int). real_of_int c * real_of_int x + Inum (real_of_int x # bs) e - real_of_int j * real_of_int k = 0)"
using zero_le_mult_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e - real_of_int j * real_of_int k"] ldcp by simp
also have "\<dots> = (\<exists> (k::int). real_of_int c * real_of_int x + Inum (real_of_int x # bs) e = real_of_int j * real_of_int k)" by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int 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\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
from cp have cnz: "c \<noteq> 0" by simp
have "c div c\<le> l div c"
by (simp add: zdiv_mono1[OF clel cp])
then have ldcp:"0 < l div c"
by (simp add: div_self[OF cnz])
have "c * (l div c) = c* (l div c) + l mod c" using d' dvd_eq_mod_eq_0[of "c" "l"] by simp
hence cl:"c * (l div c) =l" using mult_div_mod_eq [where a="l" and b="c"]
by simp
hence "(\<exists> (k::int). real_of_int l * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e = (real_of_int (l div c) * real_of_int j) * real_of_int k) = (\<exists> (k::int). real_of_int (c * (l div c)) * real_of_int x + real_of_int (l div c) * Inum (real_of_int x # bs) e = (real_of_int (l div c) * real_of_int j) * real_of_int k)" by simp
also have "\<dots> = (\<exists> (k::int). real_of_int (l div c) * (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e - real_of_int j * real_of_int k) = real_of_int (l div c)*0)" by (simp add: algebra_simps)
also fix k have "\<dots> = (\<exists> (k::int). real_of_int c * real_of_int x + Inum (real_of_int x # bs) e - real_of_int j * real_of_int k = 0)"
using zero_le_mult_iff [where a="real_of_int (l div c)" and b="real_of_int c * real_of_int x + Inum (real_of_int x # bs) e - real_of_int j * real_of_int k"] ldcp by simp
also have "\<dots> = (\<exists> (k::int). real_of_int c * real_of_int x + Inum (real_of_int x # bs) e = real_of_int j * real_of_int k)" by simp
finally show ?case using numbound0_I[OF be,where b="real_of_int (l * x)" and b'="real_of_int x" and bs="bs"] rdvd_def be isint_Mul[OF ei] mult_strict_mono[OF ldcp jp ldcp ] by simp
qed (simp_all add: numbound0_I[where bs="bs" and b="real_of_int (l * x)" and b'="real_of_int x"] isint_Mul del: of_int_mult)
lemma a_\<beta>_ex: assumes linp: "iszlfm p (a#bs)" and d: "d_\<beta> p l" and lp: "l>0"
shows "(\<exists> x. l dvd x \<and> Ifm (real_of_int x #bs) (a_\<beta> p l)) = (\<exists> (x::int). Ifm (real_of_int x#bs) p)"
(is "(\<exists> x. l dvd x \<and> ?P x) = (\<exists> x. ?P' x)")
proof-
have "(\<exists> x. l dvd x \<and> ?P x) = (\<exists> (x::int). ?P (l*x))"
using unity_coeff_ex[where l="l" and P="?P", simplified] by simp
also have "\<dots> = (\<exists> (x::int). ?P' x)" using a_\<beta>[OF linp d lp] by simp
finally show ?thesis .
qed
lemma \<beta>:
assumes lp: "iszlfm p (a#bs)"
and u: "d_\<beta> p 1"
and d: "d_\<delta> p d"
and dp: "d > 0"
and nob: "\<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> (Inum (a#bs)) ` set(\<beta> p). real_of_int x = b + real_of_int j)"
and p: "Ifm (real_of_int 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_all
with dp p c1 numbound0_I[OF bn,where b="real_of_int (x-d)" and b'="real_of_int x" and bs="bs"] 5
show ?case by (simp del: of_int_minus)
next
case (6 c e) hence c1: "c=1" and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp_all
with dp p c1 numbound0_I[OF bn,where b="real_of_int (x-d)" and b'="real_of_int x" and bs="bs"] 6
show ?case by (simp del: of_int_minus)
next
case (7 c e) hence p: "Ifm (real_of_int 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_all
let ?e = "Inum (real_of_int x # bs) e"
from ie1 have ie: "real_of_int \<lfloor>?e\<rfloor> = ?e" using isint_iff[where n="e" and bs="a#bs"]
numbound0_I[OF bn,where b="a" and b'="real_of_int x" and bs="bs"]
by (simp add: isint_iff)
{assume "real_of_int (x-d) +?e > 0" hence ?case using c1
numbound0_I[OF bn,where b="real_of_int (x-d)" and b'="real_of_int x" and bs="bs"]
by (simp del: of_int_minus)}
moreover
{assume H: "\<not> real_of_int (x-d) + ?e > 0"
let ?v="Neg e"
have vb: "?v \<in> set (\<beta> (Gt (CN 0 c e)))" by simp
from 7(5)[simplified simp_thms Inum.simps \<beta>.simps list.set bex_simps numbound0_I[OF bn,where b="a" and b'="real_of_int x" and bs="bs"]]
have nob: "\<not> (\<exists> j\<in> {1 ..d}. real_of_int x = - ?e + real_of_int j)" by auto
from H p have "real_of_int x + ?e > 0 \<and> real_of_int x + ?e \<le> real_of_int d" by (simp add: c1)
hence "real_of_int (x + \<lfloor>?e\<rfloor>) > real_of_int (0::int) \<and> real_of_int (x + \<lfloor>?e\<rfloor>) \<le> real_of_int d"
using ie by simp
hence "x + \<lfloor>?e\<rfloor> \<ge> 1 \<and> x + \<lfloor>?e\<rfloor> \<le> d" by simp
hence "\<exists> (j::int) \<in> {1 .. d}. j = x + \<lfloor>?e\<rfloor>" by simp
hence "\<exists> (j::int) \<in> {1 .. d}. real_of_int x = real_of_int (- \<lfloor>?e\<rfloor> + j)" by force
hence "\<exists> (j::int) \<in> {1 .. d}. real_of_int x = - ?e + real_of_int 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_of_int 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_of_int x # bs) e"
from ie1 have ie: "real_of_int \<lfloor>?e\<rfloor> = ?e" using numbound0_I[OF bn,where b="real_of_int x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real_of_int x)#bs"]
by (simp add: isint_iff)
{assume "real_of_int (x-d) +?e \<ge> 0" hence ?case using c1
numbound0_I[OF bn,where b="real_of_int (x-d)" and b'="real_of_int x" and bs="bs"]
by (simp del: of_int_minus)}
moreover
{assume H: "\<not> real_of_int (x-d) + ?e \<ge> 0"
let ?v="Sub (C (- 1)) e"
have vb: "?v \<in> set (\<beta> (Ge (CN 0 c e)))" by simp
from 8(5)[simplified simp_thms Inum.simps \<beta>.simps list.set bex_simps numbound0_I[OF bn,where b="a" and b'="real_of_int x" and bs="bs"]]
have nob: "\<not> (\<exists> j\<in> {1 ..d}. real_of_int x = - ?e - 1 + real_of_int j)" by auto
from H p have "real_of_int x + ?e \<ge> 0 \<and> real_of_int x + ?e < real_of_int d" by (simp add: c1)
hence "real_of_int (x + \<lfloor>?e\<rfloor>) \<ge> real_of_int (0::int) \<and> real_of_int (x + \<lfloor>?e\<rfloor>) < real_of_int d"
using ie by simp
hence "x + \<lfloor>?e\<rfloor> + 1 \<ge> 1 \<and> x + \<lfloor>?e\<rfloor> + 1 \<le> d" by simp
hence "\<exists> (j::int) \<in> {1 .. d}. j = x + \<lfloor>?e\<rfloor> + 1" by simp
hence "\<exists> (j::int) \<in> {1 .. d}. x= - \<lfloor>?e\<rfloor> - 1 + j" by (simp add: algebra_simps)
hence "\<exists> (j::int) \<in> {1 .. d}. real_of_int x= real_of_int (- \<lfloor>?e\<rfloor> - 1 + j)" by presburger
hence "\<exists> (j::int) \<in> {1 .. d}. real_of_int x= - ?e - 1 + real_of_int 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_of_int 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_of_int x # bs) e"
let ?v="(Sub (C (- 1)) e)"
have vb: "?v \<in> set (\<beta> (Eq (CN 0 c e)))" by simp
from p have "real_of_int x= - ?e" by (simp add: c1) with 3(5) show ?case using dp
by simp (erule ballE[where x="1"],
simp_all add:algebra_simps numbound0_I[OF bn,where b="real_of_int x"and b'="a"and bs="bs"])
next
case (4 c e)hence p: "Ifm (real_of_int 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_of_int x # bs) e"
let ?v="Neg e"
have vb: "?v \<in> set (\<beta> (NEq (CN 0 c e)))" by simp
{assume "real_of_int x - real_of_int d + Inum ((real_of_int (x -d)) # bs) e \<noteq> 0"
hence ?case by (simp add: c1)}
moreover
{assume H: "real_of_int x - real_of_int d + Inum ((real_of_int (x -d)) # bs) e = 0"
hence "real_of_int x = - Inum ((real_of_int (x -d)) # bs) e + real_of_int d" by simp
hence "real_of_int x = - Inum (a # bs) e + real_of_int d"
by (simp add: numbound0_I[OF bn,where b="real_of_int x - real_of_int d"and b'="a"and bs="bs"])
with 4(5) have ?case using dp by simp}
ultimately show ?case by blast
next
case (9 j c e) hence p: "Ifm (real_of_int 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_of_int x # bs) e"
from 9 have "isint e (a #bs)" by simp
hence ie: "real_of_int \<lfloor>?e\<rfloor> = ?e" using isint_iff[where n="e" and bs="(real_of_int x)#bs"] numbound0_I[OF bn,where b="real_of_int x" and b'="a" and bs="bs"]
by (simp add: isint_iff)
from 9 have id: "j dvd d" by simp
from c1 ie[symmetric] have "?p x = (real_of_int j rdvd real_of_int (x + \<lfloor>?e\<rfloor>))" by simp
also have "\<dots> = (j dvd x + \<lfloor>?e\<rfloor>)"
using int_rdvd_real[where i="j" and x="real_of_int (x + \<lfloor>?e\<rfloor>)"] by simp
also have "\<dots> = (j dvd x - d + \<lfloor>?e\<rfloor>)"
using dvd_period[OF id, where x="x" and c="-1" and t="\<lfloor>?e\<rfloor>"] by simp
also have "\<dots> = (real_of_int j rdvd real_of_int (x - d + \<lfloor>?e\<rfloor>))"
using int_rdvd_real[where i="j" and x="real_of_int (x - d + \<lfloor>?e\<rfloor>)",symmetric, simplified]
ie by simp
also have "\<dots> = (real_of_int j rdvd real_of_int x - real_of_int d + ?e)"
using ie by simp
finally show ?case
using numbound0_I[OF bn,where b="real_of_int (x-d)" and b'="real_of_int x" and bs="bs"] c1 p by simp
next
case (10 j c e) hence p: "Ifm (real_of_int 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_of_int x # bs) e"
from 10 have "isint e (a#bs)" by simp
hence ie: "real_of_int \<lfloor>?e\<rfloor> = ?e" using numbound0_I[OF bn,where b="real_of_int x" and b'="a" and bs="bs"] isint_iff[where n="e" and bs="(real_of_int x)#bs"]
by (simp add: isint_iff)
from 10 have id: "j dvd d" by simp
from c1 ie[symmetric] have "?p x = (\<not> real_of_int j rdvd real_of_int (x + \<lfloor>?e\<rfloor>))" by simp
also have "\<dots> = (\<not> j dvd x + \<lfloor>?e\<rfloor>)"
using int_rdvd_real[where i="j" and x="real_of_int (x + \<lfloor>?e\<rfloor>)"] by simp
also have "\<dots> = (\<not> j dvd x - d + \<lfloor>?e\<rfloor>)"
using dvd_period[OF id, where x="x" and c="-1" and t="\<lfloor>?e\<rfloor>"] by simp
also have "\<dots> = (\<not> real_of_int j rdvd real_of_int (x - d + \<lfloor>?e\<rfloor>))"
using int_rdvd_real[where i="j" and x="real_of_int (x - d + \<lfloor>?e\<rfloor>)",symmetric, simplified]
ie by simp
also have "\<dots> = (\<not> real_of_int j rdvd real_of_int x - real_of_int d + ?e)"
using ie by simp
finally show ?case
using numbound0_I[OF bn,where b="real_of_int (x-d)" and b'="real_of_int x" and bs="bs"] c1 p by simp
qed (auto simp add: numbound0_I[where bs="bs" and b="real_of_int (x - d)" and b'="real_of_int x"]
simp del: of_int_diff)
lemma \<beta>':
assumes lp: "iszlfm p (a #bs)"
and u: "d_\<beta> p 1"
and d: "d_\<delta> p d"
and dp: "d > 0"
shows "\<forall> x. \<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> set(\<beta> p). Ifm ((Inum (a#bs) b + real_of_int j) #bs) p) \<longrightarrow> Ifm (real_of_int x#bs) p \<longrightarrow> Ifm (real_of_int (x - d)#bs) p" (is "\<forall> x. ?b \<longrightarrow> ?P x \<longrightarrow> ?P (x - d)")
proof(clarify)
fix x
assume nb:"?b" and px: "?P x"
hence nb2: "\<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> (Inum (a#bs)) ` set(\<beta> p). real_of_int x = b + real_of_int j)"
by auto
from \<beta>[OF lp u d dp nb2 px] show "?P (x -d )" .
qed
lemma \<beta>_int: assumes lp: "iszlfm p bs"
shows "\<forall> b\<in> set (\<beta> p). isint b bs"
using lp by (induct p rule: iszlfm.induct) (auto simp add: isint_neg isint_sub)
lemma cpmi_eq:
assumes "0 < D"
and "\<exists>z::int. \<forall>x<z. P x = P1 x"
and "\<forall>x. \<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j)) \<longrightarrow> P x \<longrightarrow> P (x - D)"
and "\<forall>x k. P1 x = P1 (x - k * D)"
shows "(\<exists>x. P x) \<longleftrightarrow> ((\<exists>j\<in>{1..D}. P1 j) \<or> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j)))" (is "_=?R")
proof
assume L: "\<exists>x. P x"
show "(\<exists>j\<in>{1..D}. P1 j) \<or> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j))"
proof clarsimp
assume \<section>: "\<forall>j\<in>{1..D}. \<forall>b\<in>B. \<not> P (b + j)"
then have "\<And>k. 0\<le>k \<Longrightarrow> \<forall>x. P x \<longrightarrow> P (x - k*D)"
by (simp add: assms decr_mult_lemma)
with L \<section> assms show "\<exists>j\<in>{1..D}. P1 j"
using periodic_finite_ex [OF \<open>D>0\<close>, of P1]
by (metis abs_1 abs_add_abs abs_ge_zero decr_lemma)
qed
next
assume ?R then show "\<exists>x. P x"
using decr_lemma assms by blast
qed
theorem cp_thm:
assumes lp: "iszlfm p (a #bs)"
and u: "d_\<beta> p 1"
and d: "d_\<delta> p d"
and dp: "d > 0"
shows "(\<exists> (x::int). Ifm (real_of_int x #bs) p) = (\<exists> j\<in> {1.. d}. Ifm (real_of_int j #bs) (minusinf p) \<or> (\<exists> b \<in> set (\<beta> p). Ifm ((Inum (a#bs) b + real_of_int j) #bs) p))"
(is "(\<exists> (x::int). ?P (real_of_int x)) = (\<exists> j\<in> ?D. ?M j \<or> (\<exists> b\<in> ?B. ?P (?I b + real_of_int j)))")
proof-
from minusinf_inf[OF lp]
have th: "\<exists>(z::int). \<forall>x<z. ?P (real_of_int x) = ?M x" by blast
let ?B' = "{\<lfloor>?I b\<rfloor> | b. b\<in> ?B}"
from \<beta>_int[OF lp] isint_iff[where bs="a # bs"] have B: "\<forall> b\<in> ?B. real_of_int \<lfloor>?I b\<rfloor> = ?I b" by simp
from B[rule_format]
have "(\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (?I b + real_of_int j)) = (\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (real_of_int \<lfloor>?I b\<rfloor> + real_of_int j))"
by simp
also have "\<dots> = (\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (real_of_int (\<lfloor>?I b\<rfloor> + j)))" by simp
also have"\<dots> = (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real_of_int (b + j)))" by blast
finally have BB':
"(\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (?I b + real_of_int j)) = (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real_of_int (b + j)))"
by blast
hence th2: "\<forall> x. \<not> (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real_of_int (b + j))) \<longrightarrow> ?P (real_of_int x) \<longrightarrow> ?P (real_of_int (x - d))" using \<beta>'[OF lp u d dp] by blast
from minusinf_repeats[OF d lp]
have th3: "\<forall> 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 *)
fun \<rho> :: "fm \<Rightarrow> (num \<times> int) list" (* Compute the Reddy and Loveland Bset*)
where
"\<rho> (And p q) = (\<rho> p @ \<rho> q)"
| "\<rho> (Or p q) = (\<rho> p @ \<rho> q)"
| "\<rho> (Eq (CN 0 c e)) = [(Sub (C (- 1)) e,c)]"
| "\<rho> (NEq (CN 0 c e)) = [(Neg e,c)]"
| "\<rho> (Lt (CN 0 c e)) = []"
| "\<rho> (Le (CN 0 c e)) = []"
| "\<rho> (Gt (CN 0 c e)) = [(Neg e, c)]"
| "\<rho> (Ge (CN 0 c e)) = [(Sub (C (-1)) e, c)]"
| "\<rho> p = []"
fun \<sigma>_\<rho>:: "fm \<Rightarrow> num \<times> int \<Rightarrow> fm" (* Performs the modified substitution of Reddy and Loveland*)
where
"\<sigma>_\<rho> (And p q) = (\<lambda> (t,k). And (\<sigma>_\<rho> p (t,k)) (\<sigma>_\<rho> q (t,k)))"
| "\<sigma>_\<rho> (Or p q) = (\<lambda> (t,k). Or (\<sigma>_\<rho> p (t,k)) (\<sigma>_\<rho> q (t,k)))"
| "\<sigma>_\<rho> (Eq (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Eq (Add (Mul (c div k) t) e))
else (Eq (Add (Mul c t) (Mul k e))))"
| "\<sigma>_\<rho> (NEq (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (NEq (Add (Mul (c div k) t) e))
else (NEq (Add (Mul c t) (Mul k e))))"
| "\<sigma>_\<rho> (Lt (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Lt (Add (Mul (c div k) t) e))
else (Lt (Add (Mul c t) (Mul k e))))"
| "\<sigma>_\<rho> (Le (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Le (Add (Mul (c div k) t) e))
else (Le (Add (Mul c t) (Mul k e))))"
| "\<sigma>_\<rho> (Gt (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Gt (Add (Mul (c div k) t) e))
else (Gt (Add (Mul c t) (Mul k e))))"
| "\<sigma>_\<rho> (Ge (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Ge (Add (Mul (c div k) t) e))
else (Ge (Add (Mul c t) (Mul k e))))"
| "\<sigma>_\<rho> (Dvd i (CN 0 c e)) =(\<lambda> (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))))"
| "\<sigma>_\<rho> (NDvd i (CN 0 c e))=(\<lambda> (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))))"
| "\<sigma>_\<rho> p = (\<lambda> (t,k). p)"
fun \<alpha>_\<rho> :: "fm \<Rightarrow> (num \<times> int) list"
where
"\<alpha>_\<rho> (And p q) = (\<alpha>_\<rho> p @ \<alpha>_\<rho> q)"
| "\<alpha>_\<rho> (Or p q) = (\<alpha>_\<rho> p @ \<alpha>_\<rho> q)"
| "\<alpha>_\<rho> (Eq (CN 0 c e)) = [(Add (C (- 1)) e,c)]"
| "\<alpha>_\<rho> (NEq (CN 0 c e)) = [(e,c)]"
| "\<alpha>_\<rho> (Lt (CN 0 c e)) = [(e,c)]"
| "\<alpha>_\<rho> (Le (CN 0 c e)) = [(Add (C (- 1)) e,c)]"
| "\<alpha>_\<rho> p = []"
(* Simulates normal substituion by modifying the formula see correctness theorem *)
definition \<sigma> :: "fm \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm" where
"\<sigma> p k t \<equiv> And (Dvd k t) (\<sigma>_\<rho> p (t,k))"
lemma \<sigma>_\<rho>:
assumes linp: "iszlfm p (real_of_int (x::int)#bs)"
and kpos: "real_of_int k > 0"
and tnb: "numbound0 t"
and tint: "isint t (real_of_int x#bs)"
and kdt: "k dvd \<lfloor>Inum (b'#bs) t\<rfloor>"
shows "Ifm (real_of_int x#bs) (\<sigma>_\<rho> p (t,k)) = (Ifm ((real_of_int (\<lfloor>Inum (b'#bs) t\<rfloor> div k))#bs) p)"
(is "?I (real_of_int x) (?s p) = (?I (real_of_int (\<lfloor>?N b' t\<rfloor> div k)) p)" is "_ = (?I ?tk p)")
using linp kpos tnb
proof(induct p rule: \<sigma>_\<rho>.induct)
case (3 c e)
from 3 have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from kpos have knz': "real_of_int k \<noteq> 0" by simp
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t"
using isint_def by simp
from assms * have "?I (real_of_int x) (?s (Eq (CN 0 c e))) = ((real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k = 0)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (Eq (CN 0 c e)))"
using nonzero_eq_divide_eq[OF knz',
where a="real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e" and b="0", symmetric]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (4 c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from kpos have knz': "real_of_int k \<noteq> 0" by simp
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (NEq (CN 0 c e))) = ((real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k \<noteq> 0)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (NEq (CN 0 c e)))"
using nonzero_eq_divide_eq[OF knz',
where a="real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e" and b="0", symmetric]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (5 c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (Lt (CN 0 c e))) = ((real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k < 0)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (Lt (CN 0 c e)))"
using pos_less_divide_eq[OF kpos,
where a="real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e" and b="0", symmetric]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (6 c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (Le (CN 0 c e))) = ((real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k \<le> 0)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (Le (CN 0 c e)))"
using pos_le_divide_eq[OF kpos,
where a="real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e" and b="0", symmetric]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (7 c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (Gt (CN 0 c e))) = ((real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k > 0)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (Gt (CN 0 c e)))"
using pos_divide_less_eq[OF kpos,
where a="real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e" and b="0", symmetric]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (8 c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (Ge (CN 0 c e))) = ((real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k \<ge> 0)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (Ge (CN 0 c e)))"
using pos_divide_le_eq[OF kpos,
where a="real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e" and b="0", symmetric]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (9 i c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from kpos have knz: "k\<noteq>0" by simp hence knz': "real_of_int k \<noteq> 0" by simp
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (Dvd i (CN 0 c e))) = (real_of_int i * real_of_int k rdvd (real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k)"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (Dvd i (CN 0 c e)))"
using rdvd_mult[OF knz, where n="i"]
real_of_int_div[OF kdt] numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
next
case (10 i c e)
then have cp: "c > 0" and nb: "numbound0 e" by auto
{ assume kdc: "k dvd c"
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from kdc have ?case using real_of_int_div[OF kdc] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"] by (simp add: ti) }
moreover
{ assume *: "\<not> k dvd c"
from kpos have knz: "k\<noteq>0" by simp hence knz': "real_of_int k \<noteq> 0" by simp
from tint have ti: "real_of_int \<lfloor>?N (real_of_int x) t\<rfloor> = ?N (real_of_int x) t" using isint_def by simp
from assms * have "?I (real_of_int x) (?s (NDvd i (CN 0 c e))) = (\<not> (real_of_int i * real_of_int k rdvd (real_of_int c * (?N (real_of_int x) t / real_of_int k) + ?N (real_of_int x) e)* real_of_int k))"
using real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti algebra_simps)
also have "\<dots> = (?I ?tk (NDvd i (CN 0 c e)))"
using rdvd_mult[OF knz, where n="i"] real_of_int_div[OF kdt]
numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real_of_int x"]
numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real_of_int x"]
by (simp add: ti)
finally have ?case . }
ultimately show ?case by blast
qed (simp_all add: bound0_I[where bs="bs" and b="real_of_int (\<lfloor>?N b' t\<rfloor> div k)" and b'="real_of_int x"]
numbound0_I[where bs="bs" and b="real_of_int (\<lfloor>?N b' t\<rfloor> div k)" and b'="real_of_int x"])
lemma \<sigma>_\<rho>_nb: assumes lp:"iszlfm p (a#bs)" and nb: "numbound0 t"
shows "bound0 (\<sigma>_\<rho> p (t,k))"
using lp
by (induct p rule: iszlfm.induct, auto simp add: nb)
lemma \<rho>_l:
assumes lp: "iszlfm p (real_of_int (i::int)#bs)"
shows "\<forall> (b,k) \<in> set (\<rho> p). k >0 \<and> numbound0 b \<and> isint b (real_of_int i#bs)"
using lp by (induct p rule: \<rho>.induct, auto simp add: isint_sub isint_neg)
lemma \<alpha>_\<rho>_l:
assumes lp: "iszlfm p (real_of_int (i::int)#bs)"
shows "\<forall> (b,k) \<in> set (\<alpha>_\<rho> p). k >0 \<and> numbound0 b \<and> isint b (real_of_int i#bs)"
using lp isint_add [OF isint_c[where j="- 1"],where bs="real_of_int i#bs"]
by (induct p rule: \<alpha>_\<rho>.induct, auto)
lemma \<rho>: assumes lp: "iszlfm p (real_of_int (i::int) #bs)"
and pi: "Ifm (real_of_int i#bs) p"
and d: "d_\<delta> p d"
and dp: "d > 0"
and nob: "\<forall>(e,c) \<in> set (\<rho> p). \<forall> j\<in> {1 .. c*d}. real_of_int (c*i) \<noteq> Inum (real_of_int i#bs) e + real_of_int j"
(is "\<forall>(e,c) \<in> set (\<rho> p). \<forall> j\<in> {1 .. c*d}. _ \<noteq> ?N i e + _")
shows "Ifm (real_of_int(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_of_int i#bs)"
and pi: "real_of_int (c*i) = - 1 - ?N i e + real_of_int (1::int)" and nob: "\<forall> j\<in> {1 .. c*d}. real_of_int (c*i) \<noteq> -1 - ?N i e + real_of_int j"
by simp+
from mult_strict_left_mono[OF dp cp] have one:"1 \<in> {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_of_int i#bs)"
and nob: "\<forall> j\<in> {1 .. c*d}. real_of_int (c*i) \<noteq> - ?N i e + real_of_int j"
by simp+
{assume "real_of_int (c*i) \<noteq> - ?N i e + real_of_int (c*d)"
with numbound0_I[OF nb, where bs="bs" and b="real_of_int i - real_of_int d" and b'="real_of_int i"]
have ?case by (simp add: algebra_simps)}
moreover
{assume pi: "real_of_int (c*i) = - ?N i e + real_of_int (c*d)"
from mult_strict_left_mono[OF dp cp] have d: "(c*d) \<in> {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 5 mult_strict_left_mono[OF dp cp, simplified of_int_less_iff[symmetric]
of_int_mult]
show ?case using 5 dp
apply (simp add: numbound0_I[where bs="bs" and b="real_of_int i - real_of_int d" and b'="real_of_int i"]
algebra_simps del: mult_pos_pos)
by (metis add.right_neutral of_int_0_less_iff of_int_mult pos_add_strict)
next
case (6 c e) hence cp: "c > 0" by simp
from 6 mult_strict_left_mono[OF dp cp, simplified of_int_less_iff[symmetric]
of_int_mult]
show ?case using 6 dp
by (fastforce simp: numbound0_I[where bs="bs" and b="i - real_of_int d" and b'="i"]
algebra_simps intro: order_trans)
next
case (7 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real_of_int i#bs)"
and nob: "\<forall> j\<in> {1 .. c*d}. real_of_int (c*i) \<noteq> - ?N i e + real_of_int j"
and pi: "real_of_int (c*i) + ?N i e > 0" and cp': "real_of_int c >0"
by simp+
let ?fe = "\<lfloor>?N i e\<rfloor>"
from pi cp have th:"(real_of_int i +?N i e / real_of_int c)*real_of_int c > 0" by (simp add: algebra_simps)
from pi ei[simplified isint_iff] have "real_of_int (c*i + ?fe) > real_of_int (0::int)" by simp
hence pi': "c*i + ?fe > 0" by (simp only: of_int_less_iff[symmetric])
have "real_of_int (c*i) + ?N i e > real_of_int (c*d) \<or> real_of_int (c*i) + ?N i e \<le> real_of_int (c*d)" by auto
moreover
{assume "real_of_int (c*i) + ?N i e > real_of_int (c*d)" hence ?case
by (simp add: algebra_simps
numbound0_I[OF nb,where bs="bs" and b="real_of_int i - real_of_int d" and b'="real_of_int i"])}
moreover
{assume H:"real_of_int (c*i) + ?N i e \<le> real_of_int (c*d)"
with ei[simplified isint_iff] have "real_of_int (c*i + ?fe) \<le> real_of_int (c*d)" by simp
hence pid: "c*i + ?fe \<le> c*d" by (simp only: of_int_le_iff)
with pi' have "\<exists> j1\<in> {1 .. c*d}. c*i + ?fe = j1" by auto
hence "\<exists> j1\<in> {1 .. c*d}. real_of_int (c*i) = - ?N i e + real_of_int j1"
unfolding Bex_def using ei[simplified isint_iff] by fastforce
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_of_int i#bs)"
and nob: "\<forall> j\<in> {1 .. c*d}. real_of_int (c*i) \<noteq> - 1 - ?N i e + real_of_int j"
and pi: "real_of_int (c*i) + ?N i e \<ge> 0" and cp': "real_of_int c >0"
by simp+
let ?fe = "\<lfloor>?N i e\<rfloor>"
from pi cp have th:"(real_of_int i +?N i e / real_of_int c)*real_of_int c \<ge> 0" by (simp add: algebra_simps)
from pi ei[simplified isint_iff] have "real_of_int (c*i + ?fe) \<ge> real_of_int (0::int)" by simp
hence pi': "c*i + 1 + ?fe \<ge> 1" by (simp only: of_int_le_iff[symmetric])
have "real_of_int (c*i) + ?N i e \<ge> real_of_int (c*d) \<or> real_of_int (c*i) + ?N i e < real_of_int (c*d)" by auto
moreover
{assume "real_of_int (c*i) + ?N i e \<ge> real_of_int (c*d)" hence ?case
by (simp add: algebra_simps
numbound0_I[OF nb,where bs="bs" and b="real_of_int i - real_of_int d" and b'="real_of_int i"])}
moreover
{assume H:"real_of_int (c*i) + ?N i e < real_of_int (c*d)"
with ei[simplified isint_iff] have "real_of_int (c*i + ?fe) < real_of_int (c*d)" by simp
hence pid: "c*i + 1 + ?fe \<le> c*d" by (simp only: of_int_le_iff)
with pi' have "\<exists> j1\<in> {1 .. c*d}. c*i + 1+ ?fe = j1" by auto
hence "\<exists> j1\<in> {1 .. c*d}. real_of_int (c*i) + 1= - ?N i e + real_of_int j1"
unfolding Bex_def using ei[simplified isint_iff] by fastforce
hence "\<exists> j1\<in> {1 .. c*d}. real_of_int (c*i) = (- ?N i e + real_of_int j1) - 1"
by (simp only: algebra_simps)
hence "\<exists> j1\<in> {1 .. c*d}. real_of_int (c*i) = - 1 - ?N i e + real_of_int j1"
by (simp add: algebra_simps)
with nob have ?case by blast }
ultimately show ?case by blast
next
case (9 j c e) hence p: "real_of_int j rdvd real_of_int (c*i) + ?N i e" (is "?p x") and cp: "c > 0" and bn:"numbound0 e" by simp+
let ?e = "Inum (real_of_int i # bs) e"
from 9 have "isint e (real_of_int i #bs)" by simp
hence ie: "real_of_int \<lfloor>?e\<rfloor> = ?e" using isint_iff[where n="e" and bs="(real_of_int i)#bs"] numbound0_I[OF bn,where b="real_of_int i" and b'="real_of_int i" and bs="bs"]
by (simp add: isint_iff)
from 9 have id: "j dvd d" by simp
from ie[symmetric] have "?p i = (real_of_int j rdvd real_of_int (c*i + \<lfloor>?e\<rfloor>))" by simp
also have "\<dots> = (j dvd c*i + \<lfloor>?e\<rfloor>)"
using int_rdvd_iff [where i="j" and t="c*i + \<lfloor>?e\<rfloor>"] by simp
also have "\<dots> = (j dvd c*i - c*d + \<lfloor>?e\<rfloor>)"
using dvd_period[OF id, where x="c*i" and c="-c" and t="\<lfloor>?e\<rfloor>"] by simp
also have "\<dots> = (real_of_int j rdvd real_of_int (c*i - c*d + \<lfloor>?e\<rfloor>))"
using int_rdvd_iff[where i="j" and t="(c*i - c*d + \<lfloor>?e\<rfloor>)",symmetric, simplified]
ie by simp
also have "\<dots> = (real_of_int j rdvd real_of_int (c*(i - d)) + ?e)"
using ie by (simp add:algebra_simps)
finally show ?case
using numbound0_I[OF bn,where b="real_of_int i - real_of_int d" and b'="real_of_int i" and bs="bs"] p
by (simp add: algebra_simps)
next
case (10 j c e)
hence p: "\<not> (real_of_int j rdvd real_of_int (c*i) + ?N i e)" (is "?p x") and cp: "c > 0" and bn:"numbound0 e"
by simp+
let ?e = "Inum (real_of_int i # bs) e"
from 10 have "isint e (real_of_int i #bs)" by simp
hence ie: "real_of_int \<lfloor>?e\<rfloor> = ?e"
using isint_iff[where n="e" and bs="(real_of_int i)#bs"] numbound0_I[OF bn,where b="real_of_int i" and b'="real_of_int i" and bs="bs"]
by (simp add: isint_iff)
from 10 have id: "j dvd d" by simp
from ie[symmetric] have "?p i = (\<not> (real_of_int j rdvd real_of_int (c*i + \<lfloor>?e\<rfloor>)))" by simp
also have "\<dots> \<longleftrightarrow> \<not> (j dvd c*i + \<lfloor>?e\<rfloor>)"
using int_rdvd_iff [where i="j" and t="c*i + \<lfloor>?e\<rfloor>"] by simp
also have "\<dots> \<longleftrightarrow> \<not> (j dvd c*i - c*d + \<lfloor>?e\<rfloor>)"
using dvd_period[OF id, where x="c*i" and c="-c" and t="\<lfloor>?e\<rfloor>"] by simp
also have "\<dots> \<longleftrightarrow> \<not> (real_of_int j rdvd real_of_int (c*i - c*d + \<lfloor>?e\<rfloor>))"
using int_rdvd_iff[where i="j" and t="(c*i - c*d + \<lfloor>?e\<rfloor>)",symmetric, simplified]
ie by simp
also have "\<dots> \<longleftrightarrow> \<not> (real_of_int j rdvd real_of_int (c*(i - d)) + ?e)"
using ie by (simp add:algebra_simps)
finally show ?case
using numbound0_I[OF bn,where b="real_of_int i - real_of_int d" and b'="real_of_int i" and bs="bs"] p
by (simp add: algebra_simps)
qed (auto simp add: numbound0_I[where bs="bs" and b="real_of_int i - real_of_int d" and b'="real_of_int i"])
lemma \<sigma>_nb: assumes lp: "iszlfm p (a#bs)" and nb: "numbound0 t"
shows "bound0 (\<sigma> p k t)"
using \<sigma>_\<rho>_nb[OF lp nb] nb by (simp add: \<sigma>_def)
lemma \<rho>': assumes lp: "iszlfm p (a #bs)"
and d: "d_\<delta> p d"
and dp: "d > 0"
shows "\<forall> x. \<not>(\<exists> (e,c) \<in> set(\<rho> p). \<exists>(j::int) \<in> {1 .. c*d}. Ifm (a #bs) (\<sigma> p c (Add e (C j)))) \<longrightarrow> Ifm (real_of_int x#bs) p \<longrightarrow> Ifm (real_of_int (x - d)#bs) p" (is "\<forall> x. ?b x \<longrightarrow> ?P x \<longrightarrow> ?P (x - d)") | |