java.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33 by inductive eq ::
section \<open>Predicates as enumerations\<close>lemma eq_is_eq: "eq x y \ (x = y)"
theory importsprimrec null :: "'a seq \ bool" where begin
subsection| "null (Insert x P) \ False"
| "null (Join P xq) \ is_empty P \ null xq"
lemma java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "the_only | "the_only (if is_empty P then x else let y | "the_only default (if is_empty P then else let x = singleton default P; y = the_only java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 52
lemma null_is_empty Let_def java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0
| Insert x else let y if x = y then | Join P xq else if null else let x (auto simp add: Seq_def the_only_singleton is_empty_def by (simp add: pred_eqI)
instantiationdefinition the :: "'a pred "the A = (THE java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
struc
fun anamorph (if else of NONE => ([ | SOME (v val k' = val (vs, z) = java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 27 "Pfun yield (Seq and next Empty = | next (Insert (x, | next (Join (P of NONE => | SOME (x, Q) => java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "P < Q java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for length 0
definition "\ = Pred \"
lemma "eval lemma eval_pred_of_set [simp]: by ( "eval (pred_of_set A) set_def)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 "\ = Pred \"
lemma"set_of_pred = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 "eval \ = \" by ( by (simpjava.lang.StringIndexOutOfBoundsException: Range [0, 11) out of bounds for length 0
definition "set_of_seq = set_of_pred java.lang.StringIndexOutOfBoundsException: Range [0, 36) out of bounds for length 0
lemma lemma of_pred_code [code]: "eval ( "set_of_pred Predicate. | Predicate.Insert x P \<Rightarrow> insert x (set_of_pred P) | Predicate.Join P by (auto java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0 by
definition "\A = Pred (\(eval ` A))"
lemma eval_Inffunction iterate_upto :: "(natural java.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 5 "eval ( else Predicate.Insert (f n) (iterate_upto f (n + 1) m))" byby pat_completeness
termination by (relation (auto simp add
text \<open>Misc\<close>
lemmadeclare Inf_set_fold [wheredeclare Sup_set_fold [ " by (simp
lemma eval_SUP [simp]: showspA=Finite_Setfold PredicatesingleA"("lhs=rhs) by (simp add: image_comp)
proof (rulesym begin
interpre comp_fun_idemsup:' Predicate.pred 'a Predicate.pred \ 'a Predicate.pred"
P(P"
lemma eval_compl [simp]: "eval (- P) = from \finite\<> show ? = ?" (inductA a !:pred_eqIjava.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87
b simpa: )
definition "P-Q=Predeval P-eval Q)"
lemma eval_minus [simp]: "java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 interpret"up : apred\ 'a Predicate.pred \ 'a Predicate.pred"
instancebyfactcomp_fun_idem_sup fixshowthesis s add []java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 ">(Sup ` A) \ \(Inf ` {f ` A |f. \Y\A. f Y \ Y})" proof fix w lemmapjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 39
"pred_ofset( )=foldrs (. Predicatesingle s bot have ( add: foldr_foldfun_eq_iffjava.lang.StringIndexOutOfBoundsException: Range [72, 73) out of bounds for length 72
metisno_types java.lang.StringIndexOutOfBoundsException: Range [65, 66) out of bounds for length 65 haveopen
hide_const) eval bind i not_pred from Empty Insert Seqm pred_of_seq nullt q the
java.lang.StringIndexOutOfBoundsException: Range [9, 5) out of bounds for length 36 qed (auto intro!: pred_eqI)
end
definition single :: "'a \ 'a pred" where "single x = Pred ((=) x)"
lemma is_empty_sup: "is_empty (A \ B) \ is_empty A \ is_empty B" by (auto simp add: is_empty_def)
definition singleton :: "(unit \ 'a) \ 'a pred \ 'a" where "singleton default A = (if \!x. eval A x then THE x. eval A x else default ())" for default
lemma singleton_eqI: "\!x. eval A x \ eval A x \ singleton default A = x" for default by (auto simp add: singleton_def)
lemma eval_singletonI: "\!x. eval A x \ eval A (singleton default A)" for default proof - assume assm: "\!x. eval A x" thenobtain x where x: "eval A x" .. with assm have"singleton default A = x"by (rule singleton_eqI) with x show ?thesis by simp qed
lemma single_singleton: "\!x. eval A x \ single (singleton default A) = A" for default proof - assume assm: "\!x. eval A x" thenhave"eval A (singleton default A)" by (rule eval_singletonI) moreoverfrom assm have"\x. eval A x \ singleton default A = x" by (rule singleton_eqI) ultimatelyhave"eval (single (singleton default A)) = eval A" by (simp (no_asm_use) add: single_def fun_eq_iff) blast thenhave"\x. eval (single (singleton default A)) x = eval A x" by simp thenshow ?thesis by (rule pred_eqI) qed
lemma singleton_undefinedI: "\ (\!x. eval A x) \ singleton default A = default ()" for default by (simp add: singleton_def)
lemma singleton_bot: "singleton default \ = default ()" for default by (auto simp add: bot_pred_def intro: singleton_undefinedI)
lemma singleton_sup_single_single: "singleton default (single x \ single y) = (if x = y then x else default ())" for default proof (cases "x = y") case True thenshow ?thesis by (simp add: singleton_single) next case False have"eval (single x \ single y) x" and"eval (single x \ single y) y" by (auto intro: supI1 supI2 singleI) with False have"\ (\!z. eval (single x \ single y) z)" by blast thenhave"singleton default (single x \ single y) = default ()" by (rule singleton_undefinedI) with False show ?thesis by simp qed
lemma singleton_sup_aux: "singleton default (A \ B) = (if A = \ then singleton default B
else if B = \<bottom> then singleton default A
else singleton default
(single (singleton default A) \<squnion> single (singleton default B)))" for default proof (cases "(\!x. eval A x) \ (\!y. eval B y)") case True thenshow ?thesis by (simp add: single_singleton) next case False from False have A_or_B: "singleton default A = default () \ singleton default B = default ()" by (auto intro!: singleton_undefinedI) thenhave rhs: "singleton default
(single (singleton default A) \<squnion> single (singleton default B)) = default ()" by (auto simp add: singleton_sup_single_single singleton_single) from False have not_unique: "\ (\!x. eval A x) \ \ (\!y. eval B y)" by simp show ?thesis proof (cases "A \ \ \ B \ \") case True thenobtain a b where a: "eval A a"and b: "eval B b" by (blast elim: not_bot) with True not_unique have"\ (\!x. eval (A \ B) x)" by (auto simp add: sup_pred_def bot_pred_def) thenhave"singleton default (A \ B) = default ()" by (rule singleton_undefinedI) with True rhs show ?thesis by simp next case False thenshow ?thesis by auto qed qed
lemma singleton_sup: "singleton default (A \ B) = (if A = \ then singleton default B
else if B = \<bottom> then singleton default A
else if singleton default A = singleton default B then singleton default A else default ())" for default using singleton_sup_aux [of default A B] by (simp only: singleton_sup_single_single)
subsection \<open>Derived operations\<close>
definition if_pred :: "bool \ unit pred" where
if_pred_eq: "if_pred b = (if b then single () else \)"
definition holds :: "unit pred \ bool" where
holds_eq: "holds P = eval P ()"
definition not_pred :: "unit pred \ unit pred" where
not_pred_eq: "not_pred P = (if eval P () then \ else single ())"
primrec pred_of_seq :: "'a seq \ 'a pred" where "pred_of_seq Empty = \"
| "pred_of_seq (Insert x P) = single x \ P"
| "pred_of_seq (Join P xq) = P \ pred_of_seq xq"
definition Seq :: "(unit \ 'a seq) \ 'a pred" where "Seq f = pred_of_seq (f ())"
code_datatype Seq
primrec member :: "'a seq \ 'a \ bool" where "member Empty x \ False"
| "member (Insert y P) x \ x = y \ eval P x"
| "member (Join P xq) x \ eval P x \ member xq x"
lemma eval_member: "member xq = eval (pred_of_seq xq)" proof (induct xq) case Empty show ?case by (auto simp add: fun_eq_iff elim: botE) next case Insert show ?case by (auto simp add: fun_eq_iff elim: supE singleE intro: supI1 supI2 singleI) next case Join thenshow ?case by (auto simp add: fun_eq_iff elim: supE intro: supI1 supI2) qed
lemma single_code [code]: "single x = Seq (\u. Insert x \)" unfolding Seq_def by simp
primrec"apply" :: "('a \ 'b pred) \ 'a seq \ 'b seq" where "apply f Empty = Empty"
| "apply f (Insert x P) = Join (f x) (Join (P \ f) Empty)"
| "apply f (Join P xq) = Join (P \ f) (apply f xq)"
lemma apply_bind: "pred_of_seq (apply f xq) = pred_of_seq xq \ f" proof (induct xq) case Empty show ?case by (simp add: bottom_bind) next case Insert show ?case by (simp add: single_bind sup_bind) next case Join thenshow ?case by (simp add: sup_bind) qed
lemma bind_code [code]: "Seq g \ f = Seq (\u. apply f (g ()))" unfolding Seq_def by (rule sym, rule apply_bind)
primrec adjunct :: "'a pred \ 'a seq \ 'a seq" where "adjunct P Empty = Join P Empty"
| "adjunct P (Insert x Q) = Insert x (Q \ P)"
| "adjunct P (Join Q xq) = Join Q (adjunct P xq)"
lemma adjunct_sup: "pred_of_seq (adjunct P xq) = P \ pred_of_seq xq" by (induct xq) (simp_all add: sup_assoc sup_commute sup_left_commute)
lemma sup_code [code]: "Seq f \ Seq g = Seq (\u. case f ()
of Empty \<Rightarrow> g ()
| Insert x P \<Rightarrow> Insert x (P \<squnion> Seq g)
| Join P xq \<Rightarrow> adjunct (Seq g) (Join P xq))" proof (cases "f ()") case Empty thus ?thesis unfolding Seq_def by (simp add: sup_commute [of "\"]) next case Insert thus ?thesis unfolding Seq_def by (simp add: sup_assoc) next case Join thus ?thesis unfolding Seq_def by (simp add: adjunct_sup sup_assoc sup_commute sup_left_commute) qed
primrec contained :: "'a seq \ 'a pred \ bool" where "contained Empty Q \ True"
| "contained (Insert x P) Q \ eval Q x \ P \ Q"
| "contained (Join P xq) Q \ P \ Q \ contained xq Q"
lemma single_less_eq_eval: "single x \ P \ eval P x" by (auto simp add: less_eq_pred_def le_fun_def)
lemma less_eq_pred_code [code]: "Seq f \ Q = (case f ()
of Empty \<Rightarrow> True
| Insert x P \<Rightarrow> eval Q x \<and> P \<le> Q
| Join P xq \<Rightarrow> P \<le> Q \<and> contained xq Q)" by (cases "f ()")
(simp_all add: Seq_def single_less_eq_eval contained_less_eq)
instantiation pred :: (type) equal begin
definition equal_pred where [simp]: "HOL.equal P Q \ P = (Q :: 'a pred)"
instanceby standard simp
end
lemma [code nbe]: "HOL.equal P P \ True" for P :: "'a pred" by (fact equal_refl)
lemma [code]: "HOL.equal P Q \ P \ Q \ Q \ P" for P Q :: "'a pred" by auto
lemma [code]: "case_pred f P = f (eval P)" by (fact pred.case_eq_if)
lemma [code]: "rec_pred f P = f (eval P)" by (cases P) simp
inductive eq :: "'a \ 'a \ bool" where "eq x x"
lemma eq_is_eq: "eq x y \ (x = y)" by (rule eq_reflection) (auto intro: eq.intros elim: eq.cases)
primrec null :: "'a seq \ bool" where "null Empty \ True"
| "null (Insert x P) \ False"
| "null (Join P xq) \ is_empty P \ null xq"
primrec the_only :: "(unit \ 'a) \ 'a seq \ 'a" where "the_only default Empty = default ()"for default
| "the_only default (Insert x P) =
(if is_empty P then x else let y = singleton default P inif x = y then x else default ())" for default
| "the_only default (Join P xq) =
(if is_empty P then the_only default xq else if null xq then singleton default P
else let x = singleton default P; y = the_only default xq in if x = y then x else default ())" for default
lemma singleton_code [code]: "singleton default (Seq f) =
(case f () of
Empty \<Rightarrow> default ()
| Insert x P \<Rightarrow> if is_empty P then x
else let y = singleton default P in if x = y then x else default ()
| Join P xq \<Rightarrow> if is_empty P then the_only default xq
else if null xq then singleton default P
else let x = singleton default P; y = the_only default xq in if x = y then x else default ())" for default by (cases "f ()")
(auto simp add: Seq_def the_only_singleton is_empty_def
null_is_empty singleton_bot singleton_single singleton_sup Let_def)
definition the :: "'a pred \ 'a" where "the A = (THE x. eval A x)"
lemma the_eqI: "(THE x. eval P x) = x \ the P = x" by (simp add: the_def)
lemma the_eq [code]: "the A = singleton (\x. Code.abort (STR ''not_unique'') (\_. the A)) A" by (rule the_eqI) (simp add: singleton_def the_def)
code_reflect Predicate
datatypes pred = Seq and seq = Empty | Insert | Join
ML \<open> signature PREDICATE =
sig
val anamorph: ('a -> ('b * 'a) option) -> int -> 'a -> 'b list * 'a datatype'a pred = Seq of (unit -> 'a seq) and'a seq = Empty | Insert of 'a * 'a pred | Join of 'a pred * 'a seq
val map: ('a -> 'b) -> 'a pred -> 'b pred
val yield: 'a pred -> ('a * 'a pred) option
val yieldn: int -> 'a pred -> 'a list * 'a pred end;
structure Predicate : PREDICATE =
struct
fun anamorph f k x =
(if k = 0 then ([], x)
else case f x
of NONE => ([], x)
| SOME (v, y) => let
val k' = k - 1;
val (vs, z) = anamorph f k' y in (v :: vs, z) end);
datatype pred = datatype Predicate.pred datatype seq = datatype Predicate.seq
fun map f = @{code Predicate.map} f;
fun yield (Seq f) = next (f ()) andnext Empty = NONE
| next (Insert (x, P)) = SOME (x, P)
| next (Join (P, xq)) = (case yield P
of NONE => next xq
| SOME (x, Q) => SOME (x, Seq (fn _ => Join (Q, xq))));
fun yieldn k = anamorph yield k;
end; \<close>
text\<open>Conversion from and to sets\<close>
definition pred_of_set :: "'a set \ 'a pred" where "pred_of_set = Pred \ (\A x. x \ A)"
lemma eval_pred_of_set [simp]: "eval (pred_of_set A) x \ x \A" by (simp add: pred_of_set_def)
definition set_of_pred :: "'a pred \ 'a set" where "set_of_pred = Collect \ eval"
lemma member_set_of_pred [simp]: "x \ set_of_pred P \ Predicate.eval P x" by (simp add: set_of_pred_def)
definition set_of_seq :: "'a seq \ 'a set" where "set_of_seq = set_of_pred \ pred_of_seq"
lemma of_pred_code [code]: "set_of_pred (Predicate.Seq f) = (case f () of
Predicate.Empty \<Rightarrow> {}
| Predicate.Insert x P \<Rightarrow> insert x (set_of_pred P)
| Predicate.Join P xq \<Rightarrow> set_of_pred P \<union> set_of_seq xq)" by (auto split: seq.split simp add: eval_code)
lemma of_seq_code [code]: "set_of_seq Predicate.Empty = {}" "set_of_seq (Predicate.Insert x P) = insert x (set_of_pred P)" "set_of_seq (Predicate.Join P xq) = set_of_pred P \ set_of_seq xq" by auto
text\<open>Lazy Evaluation of an indexed function\<close>
function iterate_upto :: "(natural \ 'a) \ natural \ natural \ 'a Predicate.pred" where "iterate_upto f n m =
Predicate.Seq (%u. if n > m then Predicate.Empty
else Predicate.Insert (f n) (iterate_upto f (n + 1) m))" by pat_completeness auto
terminationby (relation "measure (%(f, n, m). nat_of_natural (m + 1 - n))")
(auto simp add: less_natural_def)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.