inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where "[] \ S\<^sub>1"
| "w \ A\<^sub>1 \ b # w \ S\<^sub>1"
| "w \ B\<^sub>1 \ a # w \ S\<^sub>1"
| "w \ S\<^sub>1 \ a # w \ A\<^sub>1"
| "w \ S\<^sub>1 \ b # w \ S\<^sub>1"
| "\v \ B\<^sub>1; v \ B\<^sub>1\ \ a # v @ w \ B\<^sub>1"
inductive_set S\<^sub>2 and A\<^sub>2 and B\<^sub>2 where "[] \ S\<^sub>2"
| "w \ A\<^sub>2 \ b # w \ S\<^sub>2"
| "w \ B\<^sub>2 \ a # w \ S\<^sub>2"
| "w \ S\<^sub>2 \ a # w \ A\<^sub>2"
| "w \ S\<^sub>2 \ b # w \ B\<^sub>2"
| "\v \ B\<^sub>2; v \ B\<^sub>2\ \ a # v @ w \ B\<^sub>2"
inductive_set S\<^sub>3 and A\<^sub>3 and B\<^sub>3 where "[] \ S\<^sub>3"
| "w \ A\<^sub>3 \ b # w \ S\<^sub>3"
| "w \ B\<^sub>3 \ a # w \ S\<^sub>3"
| "w \ S\<^sub>3 \ a # w \ A\<^sub>3"
| "w \ S\<^sub>3 \ b # w \ B\<^sub>3"
| "\v \ B\<^sub>3; w \ B\<^sub>3\ \ a # v @ w \ B\<^sub>3"
inductive_set S\<^sub>4 and A\<^sub>4 and B\<^sub>4 where "[] \ S\<^sub>4"
| "w \ A\<^sub>4 \ b # w \ S\<^sub>4"
| "w \ B\<^sub>4 \ a # w \ S\<^sub>4"
| "w \ S\<^sub>4 \ a # w \ A\<^sub>4"
| "\v \ A\<^sub>4; w \ A\<^sub>4\ \ b # v @ w \ A\<^sub>4"
| "w \ S\<^sub>4 \ b # w \ B\<^sub>4"
| "\v \ B\<^sub>4; w \ B\<^sub>4\ \ a # v @ w \ B\<^sub>4"
code_pred (expected_modes: o => bool, i => bool) S\<^sub>4p .
hide_const a b
section \<open>Semantics of programming languages\<close>
subsection \<open>IMP\<close>
type_synonym var = nat type_synonym state = "int list"
datatype com =
Skip |
Ass var "state => int" |
Seq com com | IF"state => bool" com com |
While "state => bool" com
inductive exec :: "com => state => state => bool"where "exec Skip s s" | "exec (Ass x e) s (s[x := e(s)])" | "exec c1 s1 s2 ==> exec c2 s2 s3 ==> exec (Seq c1 c2) s1 s3" | "b s ==> exec c1 s t ==> exec (IF b c1 c2) s t" | "~b s ==> exec c2 s t ==> exec (IF b c1 c2) s t" | "~b s ==> exec (While b c) s s" | "b s1 ==> exec c s1 s2 ==> exec (While b c) s2 s3 ==> exec (While b c) s1 s3"
datatype type =
Atom nat
| Fun type type (infixr\<open>\<Rightarrow>\<close> 200)
datatype dB =
Var nat
| App dB dB (infixl\<open>\<degree>\<close> 200)
| Abs type dB
primrec
nth_el :: "'a list \ nat \ 'a option" (\_\_\\ [90, 0] 91) where "[]\i\ = None"
| "(x # xs)\i\ = (case i of 0 \ Some x | Suc j \ xs \j\)"
inductive nth_el' :: "'a list \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> bool" where "nth_el' (x # xs) 0 x"
| "nth_el' xs i y \ nth_el' (x # xs) (Suc i) y"
inductive typing :: "type list \ dB \ type \ bool" (\_ \ _ : _\ [50, 50, 50] 50) where
Var [intro!]: "nth_el' env x T \ env \ Var x : T"
| Abs [intro!]: "T # env \ t : U \ env \ Abs T t : (T \ U)"
| App [intro!]: "env \ s : T \ U \ env \ t : T \ env \ (s \ t) : U"
primrec
lift :: "[dB, nat] => dB" where "lift (Var i) k = (if i < k then Var i else Var (i + 1))"
| "lift (s \ t) k = lift s k \ lift t k"
| "lift (Abs T s) k = Abs T (lift s (k + 1))"
primrec
subst :: "[dB, dB, nat] => dB" (\<open>_[_'/_]\<close> [300, 0, 0] 300) where
subst_Var: "(Var i)[s/k] =
(if k < i then Var (i - 1) else if i = k then s else Var i)"
| subst_App: "(t \ u)[s/k] = t[s/k] \ u[s/k]"
| subst_Abs: "(Abs T t)[s/k] = Abs T (t[lift s 0 / k+1])"
inductive beta :: "[dB, dB] => bool" (infixl\<open>\<rightarrow>\<^sub>\<beta>\<close> 50) where
beta [simp, intro!]: "Abs T s \ t \\<^sub>\ s[t/0]"
| appL [simp, intro!]: "s \\<^sub>\ t ==> s \ u \\<^sub>\ t \ u"
| appR [simp, intro!]: "s \\<^sub>\ t ==> u \ s \\<^sub>\ u \ t"
| abs [simp, intro!]: "s \\<^sub>\ t ==> Abs T s \\<^sub>\ Abs T t"
code_pred (expected_modes: i => i => o => bool, i => i => i => bool) typing . thm typing.equation
code_pred (modes: i => i => bool, i => o => bool as reduce') beta . thm beta.equation
| IfTrue: "bval b s \ (c\<^sub>1,s) \ t \ (IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \ t"
| IfFalse: "\bval b s \ (c\<^sub>2,s) \ t \ (IF b THEN c\<^sub>1 ELSE c\<^sub>2, s) \ t"
| WhileFalse: "\bval b s \ (WHILE b DO c,s) \ s"
| WhileTrue: "bval b s\<^sub>1 \ (c,s\<^sub>1) \ s\<^sub>2 \ (WHILE b DO c, s\<^sub>2) \ s\<^sub>3 \<Longrightarrow> (WHILE b DO c, s\<^sub>1) \<Rightarrow> s\<^sub>3"
code_pred big_step .
thm big_step.equation
definition list :: "(nat \ 'a) \ nat \ 'a list" where "list s n = map s [0 ..< n]"
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.