(* A formalisation for sequents. This is NOT polymorphic, like Sequent.thy The lack of an atomic thing causes problems when we come to prove invertibility. Having all identity sequents as being derivable is not helpful. *) theory SequentDepth2 imports "/usr/local/Isabelle2007/src/HOL/Library/Multiset" begin datatype form = At "nat" | Compound "string" "form list" datatype sequent = Sequent "form multiset" "form multiset" (" (_) \* (_)" [6,6] 5) (* We have that any step in a rule, be it a primitive rule or an instance of a rule in a derivation can be represented as a list of premisses and a conclusion. We need a list since a list is finite by definition *) types rule = "sequent list * sequent" types deriv = "sequent * nat" abbreviation multiset_plus (infixl "\" 80) where "(\ :: form multiset) \ (A :: form) \ \ + {#A#}" abbreviation multiset_minus (infixl "\" 80) where "(\ :: form multiset) \ (A :: form) \ \ - {#A#}" consts (* extend a sequent by adding another one. A form of weakening. Is this overkill by adding a sequent? *) extend :: "sequent \ sequent \ sequent" extendRule :: "sequent \ rule \ rule" (* functions to get at components of sequents *) antec :: "sequent \ form multiset" succ :: "sequent \ form multiset" mset :: "sequent \ form multiset" seq_size :: "sequent \ nat" (* Unique conclusion Property *) uniqueConclusion :: "rule set \ bool" primrec antec_def : "antec (Sequent ant suc) = ant" primrec succ_def : "succ (Sequent ant suc) = suc" primrec mset_def : "mset (Sequent ant suc) = ant + suc" primrec seq_size_def : "seq_size (Sequent ant suc) = size ant + size suc" (* Extend a sequent, and then a rule by adding seq to all premisses and the conclusion *) defs extend_def : "extend forms seq \ (antec forms + antec seq) \* (succ forms + succ seq)" defs extendRule_def : "extendRule forms R \ (map (extend forms) (fst R), extend forms (snd R))" (* The unique conclusion property. A set of rules has unique conclusion property if for any pair of rules, the conclusions being the same means the rules are the same*) defs uniqueConclusion_def : "uniqueConclusion R \ \ r1 \ R. \ r2 \ R. (snd r1 = snd r2) \ (r1 =r2)" (* The formulation of various rule sets *) (* idRules is the set containing all identity RULES *) inductive_set "idRules" where I[intro]: "([], {# At i #} \* {# At i #}) \ idRules" (* scRules is the set of all rules which have a single conclusion. This is akin to each rule having a single principal formula. We don't want rules to have no premisses, hence the restriction that ps \ [] *) inductive_set "scRules" where I[intro]: "\ mset c \ {# Compound R Fs #} ; ps \ [] \ \ (ps,c) \ scRules" (* Lemma which says these two sets are disjoint *) lemma disjointRules: assumes "r \ idRules" and "r \ scRules" shows "False" proof- obtain Ps C where "r = (Ps,C)" by (cases r) auto then have id:"(Ps,C) \ idRules" and sc:"(Ps,C) \ scRules" using assms by auto from id have "Ps = []" by (cases) auto moreover from sc have "Ps \ []" by (cases) auto ultimately show ?thesis by auto qed inductive_set extRules :: "rule set \ rule set" for R :: "rule set" where I[intro]: "r \ R \ extendRule seq r \ extRules R" (* A formulation of what it means to be a principal formula for a rule. Note that we have to build up from single conclusion rules. *) inductive leftPrincipal :: "rule \ form \ bool" where sc[intro]: "C = ({#Compound F Fs#} \* {#}) \ leftPrincipal (Ps,C) (Compound F Fs)" inductive rightPrincipal :: "rule \ form \ bool" where sc[intro]: "C = ({#} \* {#Compound F Fs#}) \ rightPrincipal (Ps,C) (Compound F Fs)" (* What it means to be a derivable sequent. Can have this as a predicate or as a set. The two formation rules say that the supplied premisses are derivable, and the second says that if all the premisses of some rule are derivable, then so is the conclusion. *) inductive_set derivable :: "rule set \ deriv set" for R :: "rule set" where base[intro]: "\([],C) \ R\ \ (C,0) \ derivable R" | step[intro]: "\ r \ R ; (fst r)\[] ; \ p \ set (fst r). \ n \ m. (p,n) \ derivable R \ \ (snd r,m + 1) \ derivable R" (* Characterisation of a sequent *) lemma characteriseSeq: shows "\ A B. (C :: sequent) = (A \* B)" apply (rule_tac x="antec C" in exI, rule_tac x="succ C" in exI) by (cases C) (auto) (* Helper function for later *) lemma nonEmptySet: shows "A \ [] \ (\ a. a \ set A)" by (auto simp add:neq_Nil_conv) (* Lemma which says that if we have extended an identity rule, then the propositional variable is contained in the extended multisets *) lemma extendID: assumes "extend S ({# At i #} \* {# At i #}) = (\ \* \)" shows "At i :# \ \ At i :# \" using assms proof- from assms have "\ \' \'. \ = \' \ At i \ \ = \' \ At i" using extend_def[where forms=S and seq="{# At i #} \* {# At i #}"] by (rule_tac x="antec S" in exI,rule_tac x="succ S" in exI) auto then show ?thesis by auto qed (* Lemma that says if a propositional variable is in both the antecedent and succedent of a sequent, then it is derivable from idscRules *) lemma containID: assumes a:"At i :# \ \ At i :# \" and b:"idRules \ R" shows "(\ \* \,0) \ derivable (extRules R)" proof- from a have "\ = \ \ At i \ At i \ \ = \ \ At i \ At i" using elem_imp_eq_diff_union by auto then have "extend ((\ \ At i) \* (\ \ At i)) ({# At i #} \* {# At i #}) = (\ \* \)" using extend_def[where forms="\ \ At i \* \ \ At i" and seq="{#At i#} \* {#At i#}"] by auto moreover have "([],{# At i #} \* {# At i #}) \ R" using b by auto ultimately have "([],\ \* \) \ extRules R" using extRules.I[where R=R and r="([], {#At i#} \* {#At i#})" and seq="\ \ At i \* \ \ At i"] and extendRule_def[where forms="\ \ At i \* \ \ At i" and R="([], {#At i#} \* {#At i#})"] by auto then show ?thesis using derivable.base[where R="extRules R" and C="\ \* \"] by auto qed (* Lemma which says that if r is an identity rule, then r is of the form ([], P \* P) *) lemma characteriseID: assumes "r \ idRules" shows "\ i. r = ([], {# At i #} \* {# At i #})" proof- obtain x y where "r = (x,y)" by (cases r) with `r \ idRules` have "(x,y) \ idRules" by simp then obtain i where "x=[]" and "y = ({# At i #} \* {# At i #})" by cases with `r= (x,y)` have "r = ([],{# At i #} \* {# At i #})" by simp then show "\ i. r = ([],{# At i #} \* {# At i #})" by auto qed (* A lemma about the last rule used in a derivation, i.e. that one exists *) lemma characteriseLast: assumes "(C,m+1) \ derivable R" shows "\ Ps. Ps \ [] \ (Ps,C) \ R \ (\ p \ set Ps. \ n\m. (p,n) \ derivable R)" using assms proof (cases) case (base D) then show "\ Ps. Ps \ [] \ (Ps,C) \ R \ (\ p \ set Ps. \ n\m. (p,n) \ derivable R)" using assms by simp next case (step r n) then obtain Ps where "r = (Ps,C)" and "m=n" by (cases r) (auto) then have "fst r = Ps" and "snd r = C" by auto then show "\ Ps. Ps \ [] \ (Ps,C) \ R \ (\ p \ set Ps. \ n\m. (p,n) \ derivable R)" using `r \ R` and `m=n` and prems(5,6) by (rule_tac x=Ps in exI) (auto) qed (* Lemma which says that if rule is an scRule, then the succedent is either empty, or a single formula *) lemma succ_scRule: assumes "(Ps,\ \* \) \ scRules" shows "\ = {#} \ (\ A. \ = {#A#})" using assms proof (cases) case (I d R Rs ts) then show "\ = {#} \ (\ A. \ = {#A#})" using mset_def[where ant=\ and suc=\] and union_is_single[where M=\ and N=\ and a="Compound R Rs"] by (simp,elim disjE) (auto) qed (* Equivalent, but the antecedent *) lemma antec_scRule: assumes "(Ps,\ \* \) \ scRules" shows "\ = {#} \ (\ A. \ = {#A#})" using assms proof (cases) case (I d R Rs ts) then show "\ = {#} \ (\ A. \ = {#A#})" using mset_def[where ant=\ and suc=\] and union_is_single[where M=\ and N=\ and a="Compound R Rs"] by (simp,elim disjE) (auto) qed lemma scRule_Size: assumes "r \ scRules" shows "seq_size (snd r) = 1" using assms proof- obtain Ps C where "r = (Ps,C)" by (cases r) then have "(Ps,C) \ scRules" using assms by simp then show ?thesis proof (cases) case (I D R Rs Ts) obtain G H where "D = (G \* H)" by (cases D) (auto) then have "G + H = {#Compound R Rs#}" using mset_def and `mset D \ {#Compound R Rs#}` by auto then have "size (G+H) = 1" by auto then have "size G + size H = 1" by auto then have "seq_size D = 1" using seq_size_def[where ant=G and suc=H] and `D = (G \* H)` by auto moreover have "snd r = D" using `r = (Ps,C)` and `C=D` by simp ultimately show "seq_size (snd r) = 1" by simp qed qed lemma scRuleCharacterise: assumes "(Ps,C) \ scRules" shows "\ F Fs. C = ({#} \* {#Compound F Fs#}) \ C = ({#Compound F Fs#} \* {#})" using assms proof (cases) case (I c F Fs Ps) then obtain \ \ where "c = (\ \* \)" using characteriseSeq[where C=c] by auto then have "(Ps,\ \* \) \ scRules" using prems by simp then have "\ F Fs. c = ({#} \* {#Compound F Fs#}) \ c = ({#Compound F Fs#} \* {#})" using `mset c \ {#Compound F Fs#}` and `c= (\ \* \)` and mset_def[where ant=\ and suc=\] and union_is_single[where M=\ and N=\ and a="Compound F Fs"] by auto thus ?thesis using `C=c` by simp qed lemma scExtend: assumes "r \ scRules" and "extendRule S r \ scRules" shows "S = ({#} \* {#})" using assms proof- obtain \ \ where "S = (\ \* \)" using characteriseSeq[where C=S] by auto obtain Ps C where "r = (Ps,C)" by (cases r) (auto) then have "extendRule S r = (map (extend (\ \* \)) Ps, extend S C)" using `S = (\ \* \)` and extendRule_def[where forms=S and R="(Ps,C)"] by auto then have "(map (extend (\ \* \)) Ps, extend S C) \ scRules" using `extendRule S r \ scRules` by auto from `r = (Ps,C)` obtain F Fs where "C = ({#} \* {#Compound F Fs#}) \ C = ({#Compound F Fs#} \* {#})" using `r \ scRules` and scRuleCharacterise[where Ps=Ps and C=C] by auto moreover {assume "C = ({#} \* {#Compound F Fs#})" then have "extend S C = (\ \* \ \ Compound F Fs)" using `S = (\ \* \)` and extend_def[where forms=S and seq=C] by auto then have "(map (extend (\ \* \)) Ps, \ \* \ \ Compound F Fs) \ scRules" using `(map (extend (\ \* \)) Ps, extend S C) \ scRules` by auto then obtain T Ts where "(\ \* \ \ Compound F Fs) = ({#} \* {#Compound T Ts#}) \ (\ \* \ \ Compound F Fs) = ({#Compound T Ts#} \* {#})" using scRuleCharacterise[where Ps="map (extend (\ \* \)) Ps" and C="\ \* \ \ Compound F Fs"] by auto moreover {assume eq:"(\ \* \ \ Compound F Fs) = ({#} \* {#Compound T Ts#})" then have "\ \ Compound F Fs = {#Compound T Ts#}" by auto then have "F=T" and "Fs = Ts" and "\ = {#}" by (auto simp add:union_is_single) moreover from eq have "\ = {#}" by auto ultimately have "S = ({#} \* {#})" using `S = (\ \* \)` by simp } moreover {assume eq:"(\ \* \ \ Compound F Fs) = ({#Compound T Ts#} \* {#})" then have "\ \ Compound F Fs = {#}" by auto then have "S = ({#} \* {#})" by auto } ultimately have "S = ({#} \* {#})" by blast } moreover {assume "C = ({#Compound F Fs#} \* {#})" then have "extend S C = (\ \ Compound F Fs \* \)" using `S = (\ \* \)` and extend_def[where forms=S and seq=C] by auto then have "(map (extend (\ \* \)) Ps, \ \ Compound F Fs \* \) \ scRules" using `(map (extend (\ \* \)) Ps, extend S C) \ scRules` by auto then obtain T Ts where "(\ \ Compound F Fs \* \) = ({#} \* {#Compound T Ts#}) \ (\ \ Compound F Fs \* \) = ({#Compound T Ts#} \* {#})" using scRuleCharacterise[where Ps="map (extend (\ \* \)) Ps" and C="\ \ Compound F Fs \* \"] by auto moreover {assume eq:"(\ \ Compound F Fs \* \) = ({#} \* {#Compound T Ts#})" then have "S = ({#} \* {#})" by auto } moreover {assume eq:"(\ \ Compound F Fs \* \) = ({#Compound T Ts#} \* {#})" then have "\ \ Compound F Fs = {#Compound T Ts#}" by auto then have "\ = {#}" by (auto simp add:union_is_single) moreover from eq have "\ = {#}" by auto ultimately have "S = ({#} \* {#})" using `S = (\ \* \)` by auto } ultimately have "S = ({#} \* {#})" by blast } ultimately show "S = ({#} \* {#})" by blast qed lemma extendEmpty: shows "extend ({#} \* {#}) C = C" apply (auto simp add:extend_def) by (cases C) auto lemma extendContain: assumes "r = (ps,c)" and "(Ps,C) = extendRule S r" and "p \ set ps" shows "extend S p \ set Ps" proof- from `p \ set ps` have "extend S p \ set (map (extend S) ps)" by auto moreover from `(Ps,C) = extendRule S r` and `r = (ps,c)` have "map (extend S) ps = Ps" by (simp add:extendRule_def) ultimately show ?thesis by auto qed end