theory MelhamQ imports Main begin constdefs (* P is Inf(inite) if it is true infintely often - i.e. for every time t, there's a later time t' such that P t' is true. Inf P is an assumption used to show the consistency lemma for Timeof. *) "Inf (P::nat\bool) \ \ t. \ t'. t' > t \ P t'" constdefs (* Next t' t P is true iff t' is the next time after t such the P is true (and all values t'', between t and t' are false): Time - - - t' <- t'' -> t --> P F F F T F T *) "Next t' t (P::nat\bool) \ t' < t \ P t \ (\ t''. t' < t'' \ t'' < t \ \ P t'')" consts Istimeof::"(nat\bool)\nat\nat\bool" (* Istimeof P n t is true if P is true for the n'th time at time t. (it's true for the 0'th time at time t, if there are no times before t when P is true) In the second clause, t' is before t. *) primrec "Istimeof P 0 t = (P t \ \(\ t' < t. P t'))" "Istimeof P (Suc n) t = (\t'. Istimeof P n t' \ Next t' t P)" constdefs (* Timeof is the inverse of Istimeof - it's necessary to show \!t. Istimeof P n t (under some assumptions) in order to show consistency. *) "Timeof P n \ (\ t. Istimeof P n t)" (* *********************************************************************** *) (* Well ordering property of nat *) (* If P is ever true, then there's a minimum value, n, representing the first value for which P is true. *) lemma wo1[rule_format]:"\P n. (P::nat\bool) n \ (\n. P n \ (\m P m))" apply(induct_tac n rule:less_induct) by(auto) (* Again, with HOL ALL quantifier on P *) lemma wo2:"(\ P::nat\bool. (\ n. P n) \ (\ n. P n \ (\m. m < n \ \(P m))))" by(auto simp add:wo1) (* Again, with no quantifier on P *) lemma wo3:"(\ n. (P::nat\bool) n) \ (\ n. P n \ (\ m. m < n \ \(P m)))" by(simp add:wo2) (* *********************************************************************** *) lemma inf_ex:"Inf P \ Ex P" by(auto simp add: Inf_def) (* *********************************************************************** *) (* Theorem 6.1 - "The proof of this theorem proceeds by proving the existence and uniqueness parts separately *) lemma "Inf P \ (\!t. Istimeof P n t)" apply(rule)apply(rule) -- "Subgoals are" -- "1. Inf P \ \t. Istimeof P n t" -- "2. \t y. \Inf P; Istimeof P n t; Istimeof P n y\ \ t = y" oops lemma "Inf P \ (\!t. Istimeof P n t)" proof - have exists:"Inf P \ (\t. Istimeof P n t)" proof (induct n) case 0 have ex2:"Inf P \ (\ n. P n \ (\ m. m < n \ \(P m)))" proof assume "Inf P" then have "Ex P" by (simp add: inf_ex) then show "(\ n. P n \ (\ m. m < n \ \(P m)))" by (simp add: wo3) qed then show ?case by simp next case Suc -- "\n. Inf P \ (\t. Istimeof P n t) \ Inf P \ (\t. Istimeof P (Suc n) t)" show ?case (* Now have to show: Inf P \ \t t'. Istimeof P n_ t' \ Next t' t P using the premise: Inf P \ (\t. Istimeof P n_ t) The goal isn't true without the premise because in general, there isn't always a preceeding time t', where Istime P n_ t' is true (i.e. it's not true when P is true for the first time) However, the premise ensures that the preceeding time does exist. I've tried using rule_tac x="SOME n. n' > t \ P t'" in exI (because Inf P \ \ t. \ t'. t' > t \ P t') without success. *) sorry qed have unique:"\t y. \Inf P; Istimeof P n t; Istimeof P n y\ \ t = y" sorry show ?thesis using exists unique by(auto) qed (* Here's a simpler uniqueness proof I can't do\ *) lemma "Inf P \ (\!t. P t \ (\ t'< t. \ P t))" proof - have ex:"Inf P \ (\t. P t \ (\t' P t))" sorry have uniq:"\t y. \Inf P; P t \ (\t' P t); P y \ (\t' P y)\ \ t = y" sorry then show ?thesis using ex uniq by auto qed (* Manually unfolding Inf, but instead making the quantifiers range over the whole expression allows the following theorems to be shown (p.101-102) *) lemma "\P. \t. \t'. t < t' \ P t' \ (\ n. Istimeof P n (Timeof P n))" (* *) by(auto) lemma "\P. \t. \t'. t < t' \ P t' \ (\ n. P (Timeof P n))" by(auto) lemma "\P. \t. \t'. t < t' \ P t' \ (\ t. t< (Timeof P 0) \ \(P t))" by(auto) lemma "\P. \t. \t'. t < t' \ P t' \ (\ n. (Timeof P n) < (Timeof P (n+1)))" by(auto) lemma "\P. \t. \t'. t < t' \ P t' \ (\ n. (Timeof P n) < t \ t < (Timeof P (n+1)) \ \(P t))" by(auto) (* Correctness of a delay component, using unfolded definition of Inf *) constdefs "Rise ck (t::nat) \ \ ck(t) \ ck(t+1)" "Dtype ck d q \ \ t. q(t + 1) = (if Rise ck t then d t else q t)" constdefs "Incr f \ \ t1 t2. (t1 < t2) \ (f t1 < f t2)" lemma "\ f t1 t2. (t1 < t2) \ (f t1 < f t2) = (\ P. Inf P \ ( f = Timeof P))" sorry constdefs when::"(nat\'a)\(nat\bool)\(nat\'a)" (infix "when" 20) "s when P \ s o (Timeof P)" constdefs "Del i o' \ (\t. o'(t+1) = i t)" lemma "\ck. \t. \t'. t < t' \ (Rise ck) t' \ (\ d q. Dtype ck d q \ Del(d when (Rise ck)) (q when (Rise ck)) )" by(auto) lemma bb[rule_format]:"(\ t. q(t+1) = (if (P::nat\bool) t then d t else q t)) \ (\ t. P t \ (\ n. (\ t'. t< t' \ t' < t + n + 1 \ \(P t')) \ (q (t + n + 1) = d t)))" apply(rule, rule, rule, rule) apply(induct_tac n) by(auto) end