Theory Formula
section "Formula"
theory Formula
imports Base
begin
subsection "Variables"
datatype vbl = X nat
primrec deX :: "vbl => nat" where "deX (X n) = n"
lemma X_deX[simp]: "X (deX a) = a"
by(cases a) simp
definition "zeroX = X 0"
primrec
nextX :: "vbl => vbl" where
"nextX (X n) = X (Suc n)"
definition
vblcase :: "['a,vbl => 'a,vbl] => 'a" where
"vblcase a f n = (@z. (n=zeroX ⟶ z=a) ∧ (!x. n=nextX x ⟶ z=f(x)))"
declare [[case_translation vblcase zeroX nextX]]
definition
freshVar :: "vbl set => vbl" where
"freshVar vs = X (LEAST n. n ∉ deX ` vs)"
lemma nextX_nextX[iff]: "nextX x = nextX y = (x = y)"
by(cases x, cases y) auto
lemma inj_nextX: "inj nextX"
by(auto simp add: inj_on_def)
lemma ind': "P zeroX ==> (! v . P v --> P (nextX v)) ==> P v'"
apply (case_tac v', simp)
apply(rename_tac nat)
apply(induct_tac nat)
apply(simp add: zeroX_def)
apply(rename_tac n)
apply (drule_tac x="X n" in spec, simp)
done
lemma ind: "⟦ P zeroX; ⋀ v. P v ⟹ P (nextX v) ⟧ ⟹ P v'"
apply(rule ind') by auto
lemma zeroX_nextX[iff]: "zeroX ~= nextX a"
apply(case_tac a)
apply(simp add: zeroX_def)
done
lemmas nextX_zeroX[iff] = not_sym[OF zeroX_nextX]
lemma nextX: "nextX (X n) = X (Suc n)"
apply simp done
lemma vblcase_zeroX[simp]: "vblcase a b zeroX = a"
by(simp add: vblcase_def)
lemma vblcase_nextX[simp]: "vblcase a b (nextX n) = b n"
by(simp add: vblcase_def)
lemma vbl_cases: "x = zeroX | (? y . x = nextX y)"
apply(case_tac x, rename_tac m)
apply(case_tac m)
apply(simp add: zeroX_def)
apply(rule disjI2)
apply (rule_tac x="X nat" in exI, simp)
done
lemma vbl_casesE: "⟦ x = zeroX ⟹ P; ⋀ y. x = nextX y ⟹ P ⟧ ⟹ P"
apply(auto intro: vbl_cases[elim_format]) done
lemma comp_vblcase: "f o vblcase a b = vblcase (f a) (f o b)"
apply(rule ext)
apply(rule_tac x = x in vbl_casesE)
apply(simp_all add: vblcase_zeroX vblcase_nextX)
done
lemma equalOn_vblcaseI': "equalOn (preImage nextX A) f g ==> equalOn A (vblcase x f) (vblcase x g)"
apply(simp add: equalOn_def)
apply(rule+)
apply (case_tac xa rule: vbl_casesE, simp, simp)
apply(drule_tac x=y in bspec)
apply(simp add: preImage_def)
by assumption
lemma equalOn_vblcaseI: "(zeroX : A --> x=y) ==> equalOn (preImage nextX A) f g ==> equalOn A (vblcase x f) (vblcase y g)"
apply (rule equalOnI, rule)
apply (case_tac xa rule: vbl_casesE, simp, simp)
apply(simp add: preImage_def equalOn_def)
done
lemma X_deX_connection: "X n : A = (n : (deX ` A))"
by force
lemma finiteFreshVar: "finite A ==> freshVar A ~: A"
apply(simp add: freshVar_def)
apply(simp add: X_deX_connection)
apply(rule_tac LeastI_ex)
apply(rule_tac x="(Suc (Max (deX ` A)))" in exI)
apply(rule natset_finite_max)
by force
lemma freshVarI: "[| finite A; B <= A |] ==> freshVar A ~: B"
apply(auto dest!: finiteFreshVar) done
lemma freshVarI2: "finite A ==> !x . x ~: A --> P x ==> P (freshVar A)"
apply(auto dest!: finiteFreshVar) done
lemmas vblsimps = vblcase_zeroX vblcase_nextX zeroX_nextX
nextX_zeroX nextX_nextX comp_vblcase
subsection "Predicates"
datatype predicate = Predicate nat
datatype signs = Pos | Neg
lemma signsE: "⟦ signs = Neg ⟹ P; signs = Pos ⟹ P ⟧ ⟹ P"
apply(cases signs, auto) done
lemma expand_case_signs: "Q(case_signs vpos vneg F) = (
(F = Pos --> Q (vpos)) &
(F = Neg --> Q (vneg))
)"
by(induct F) simp_all
primrec sign :: "signs ⇒ bool ⇒ bool"
where
"sign Pos x = x"
| "sign Neg x = (¬ x)"
lemma sign_arg_cong: "x = y ==> sign z x = sign z y" by simp
primrec invSign :: "signs ⇒ signs"
where
"invSign Pos = Neg"
| "invSign Neg = Pos"
subsection "Formulas"