diff -r 968c33be5c96 -r 41ce0b56d858 src/HOL/Predicate_Compile_Examples/Predicate_Compile_Examples.thy --- a/src/HOL/Predicate_Compile_Examples/Predicate_Compile_Examples.thy Mon Sep 13 16:44:19 2010 +0200 +++ b/src/HOL/Predicate_Compile_Examples/Predicate_Compile_Examples.thy Mon Sep 13 16:44:20 2010 +0200 @@ -1521,6 +1521,64 @@ thm is_error''.equation +section {* Another function example *} + +consts f :: "'a \ 'a" + +inductive fun_upd :: "(('a * 'b) * ('a \ 'b)) \ ('a \ 'b) \ bool" +where + "fun_upd ((x, a), s) (s(x := f a))" + +code_pred fun_upd . + +thm fun_upd.equation + +section {* Another semantics *} + +types + name = nat --"For simplicity in examples" + state' = "name \ nat" + +datatype aexp = N nat | V name | Plus aexp aexp + +fun aval :: "aexp \ state' \ nat" where +"aval (N n) _ = n" | +"aval (V x) st = st x" | +"aval (Plus e\<^isub>1 e\<^isub>2) st = aval e\<^isub>1 st + aval e\<^isub>2 st" + +datatype bexp = B bool | Not bexp | And bexp bexp | Less aexp aexp + +primrec bval :: "bexp \ state' \ bool" where +"bval (B b) _ = b" | +"bval (Not b) st = (\ bval b st)" | +"bval (And b1 b2) st = (bval b1 st \ bval b2 st)" | +"bval (Less a\<^isub>1 a\<^isub>2) st = (aval a\<^isub>1 st < aval a\<^isub>2 st)" + +datatype + com' = SKIP + | Assign name aexp ("_ ::= _" [1000, 61] 61) + | Semi com' com' ("_; _" [60, 61] 60) + | If bexp com' com' ("IF _ THEN _ ELSE _" [0, 0, 61] 61) + | While bexp com' ("WHILE _ DO _" [0, 61] 61) + +inductive + big_step :: "com' * state' \ state' \ bool" (infix "\" 55) +where + Skip: "(SKIP,s) \ s" +| Assign: "(x ::= a,s) \ s(x := aval a s)" + +| Semi: "(c\<^isub>1,s\<^isub>1) \ s\<^isub>2 \ (c\<^isub>2,s\<^isub>2) \ s\<^isub>3 \ (c\<^isub>1;c\<^isub>2, s\<^isub>1) \ s\<^isub>3" + +| IfTrue: "bval b s \ (c\<^isub>1,s) \ t \ (IF b THEN c\<^isub>1 ELSE c\<^isub>2, s) \ t" +| IfFalse: "\bval b s \ (c\<^isub>2,s) \ t \ (IF b THEN c\<^isub>1 ELSE c\<^isub>2, s) \ t" + +| WhileFalse: "\bval b s \ (WHILE b DO c,s) \ s" +| WhileTrue: "bval b s\<^isub>1 \ (c,s\<^isub>1) \ s\<^isub>2 \ (WHILE b DO c, s\<^isub>2) \ s\<^isub>3 + \ (WHILE b DO c, s\<^isub>1) \ s\<^isub>3" + +code_pred big_step . + +thm big_step.equation section {* Examples for detecting switches *}