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 (metis Suc_inject nextX.simps vbl.exhaust vbl.inject)
lemma inj_nextX: "inj nextX"
by(auto simp add: inj_on_def)
lemma ind:
assumes "P zeroX" "⋀ v. P v ⟹ P (nextX v)"
shows "P v'"
proof -
have "P (X n)" for n
by (induction n) (use assms zeroX_def nextX_def in force)+
then show ?thesis
by (metis X_deX)
qed
lemma zeroX_nextX[iff]: "zeroX ≠ nextX a"
by (metis nat.discI nextX.simps vbl.exhaust vbl.inject zeroX_def)
lemmas nextX_zeroX[iff] = not_sym[OF zeroX_nextX]
lemma nextX: "nextX (X n) = X (Suc n)"
by simp
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)"
by (metis X_deX nextX old.nat.exhaust zeroX_def)
lemma vbl_casesE: "⟦ x = zeroX ⟹ P; ⋀ y. x = nextX y ⟹ P ⟧ ⟹ P"
using vbl_cases by blast
lemma comp_vblcase: "f ∘ vblcase a b = vblcase (f a) (f ∘ b)"
proof
fix x
show "(f ∘ vblcase a b) x = (case x of zeroX ⇒ f a | nextX x ⇒ (f ∘ b) x)"
using vbl_cases [of x] by auto
qed
lemma equalOn_vblcaseI': "equalOn (preImage nextX A) f g ⟹ equalOn A (vblcase x f) (vblcase x g)"
unfolding equalOn_def
by (metis vbl_casesE vblcase_nextX vblcase_zeroX vimageI2)
lemma equalOn_vblcaseI: "(zeroX ∈ A ⟹ x=y) ⟹ equalOn (preImage nextX A) f g ⟹ equalOn A (vblcase x f) (vblcase y g)"
by (smt (verit) equalOnD equalOnI equalOn_vblcaseI' vbl_casesE vblcase_nextX)
lemma X_deX_connection: "X n ∈ A = (n ∈ (deX ` A))"
by force
lemma finiteFreshVar: "finite A ⟹ freshVar A ∉ A"
unfolding freshVar_def
by (metis (no_types, lifting) LeastI_ex X_deX finite_imageI
finite_nat_set_iff_bounded image_eqI order_less_imp_triv
vbl.inject)
lemma freshVarI: "⟦finite A; B ⊆ A⟧ ⟹ freshVar A ∉ B"
using finiteFreshVar in_mono by blast
lemma freshVarI2: "⟦finite A; ⋀x . x ∉ A ⟹ P x⟧ ⟹ P (freshVar A)"
using finiteFreshVar by presburger
lemmas vblsimps = vblcase_zeroX vblcase_nextX zeroX_nextX
nextX_zeroX nextX_nextX comp_vblcase
subsection "Predicates"
datatype predicate = Predicate nat
datatype signs = Pos | Neg
primrec sign :: "signs ⇒ bool ⇒ bool"
where
"sign Pos x = x"
| "sign Neg x = (¬ x)"
primrec invSign :: "signs ⇒ signs"
where
"invSign Pos = Neg"
| "invSign Neg = Pos"
subsection "Formulas"