src/HOL/Predicate_Compile_Examples/Predicate_Compile_Examples.thy
changeset 39313 41ce0b56d858
parent 39275 dd84daec5d3c
child 39438 c5ece2a7a86e
child 39467 139c694299f6
equal deleted inserted replaced
39312:968c33be5c96 39313:41ce0b56d858
  1519 
  1519 
  1520 code_pred is_error'' .
  1520 code_pred is_error'' .
  1521 
  1521 
  1522 thm is_error''.equation
  1522 thm is_error''.equation
  1523 
  1523 
       
  1524 section {* Another function example *}
       
  1525 
       
  1526 consts f :: "'a \<Rightarrow> 'a"
       
  1527 
       
  1528 inductive fun_upd :: "(('a * 'b) * ('a \<Rightarrow> 'b)) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
       
  1529 where
       
  1530   "fun_upd ((x, a), s) (s(x := f a))"
       
  1531 
       
  1532 code_pred fun_upd .
       
  1533 
       
  1534 thm fun_upd.equation
       
  1535 
       
  1536 section {* Another semantics *}
       
  1537 
       
  1538 types
       
  1539   name = nat --"For simplicity in examples"
       
  1540   state' = "name \<Rightarrow> nat"
       
  1541 
       
  1542 datatype aexp = N nat | V name | Plus aexp aexp
       
  1543 
       
  1544 fun aval :: "aexp \<Rightarrow> state' \<Rightarrow> nat" where
       
  1545 "aval (N n) _ = n" |
       
  1546 "aval (V x) st = st x" |
       
  1547 "aval (Plus e\<^isub>1 e\<^isub>2) st = aval e\<^isub>1 st + aval e\<^isub>2 st"
       
  1548 
       
  1549 datatype bexp = B bool | Not bexp | And bexp bexp | Less aexp aexp
       
  1550 
       
  1551 primrec bval :: "bexp \<Rightarrow> state' \<Rightarrow> bool" where
       
  1552 "bval (B b) _ = b" |
       
  1553 "bval (Not b) st = (\<not> bval b st)" |
       
  1554 "bval (And b1 b2) st = (bval b1 st \<and> bval b2 st)" |
       
  1555 "bval (Less a\<^isub>1 a\<^isub>2) st = (aval a\<^isub>1 st < aval a\<^isub>2 st)"
       
  1556 
       
  1557 datatype
       
  1558   com' = SKIP 
       
  1559       | Assign name aexp         ("_ ::= _" [1000, 61] 61)
       
  1560       | Semi   com'  com'          ("_; _"  [60, 61] 60)
       
  1561       | If     bexp com' com'     ("IF _ THEN _ ELSE _"  [0, 0, 61] 61)
       
  1562       | While  bexp com'         ("WHILE _ DO _"  [0, 61] 61)
       
  1563 
       
  1564 inductive
       
  1565   big_step :: "com' * state' \<Rightarrow> state' \<Rightarrow> bool" (infix "\<Rightarrow>" 55)
       
  1566 where
       
  1567   Skip:    "(SKIP,s) \<Rightarrow> s"
       
  1568 | Assign:  "(x ::= a,s) \<Rightarrow> s(x := aval a s)"
       
  1569 
       
  1570 | Semi:    "(c\<^isub>1,s\<^isub>1) \<Rightarrow> s\<^isub>2  \<Longrightarrow>  (c\<^isub>2,s\<^isub>2) \<Rightarrow> s\<^isub>3  \<Longrightarrow> (c\<^isub>1;c\<^isub>2, s\<^isub>1) \<Rightarrow> s\<^isub>3"
       
  1571 
       
  1572 | IfTrue:  "bval b s  \<Longrightarrow>  (c\<^isub>1,s) \<Rightarrow> t  \<Longrightarrow>  (IF b THEN c\<^isub>1 ELSE c\<^isub>2, s) \<Rightarrow> t"
       
  1573 | IfFalse: "\<not>bval b s  \<Longrightarrow>  (c\<^isub>2,s) \<Rightarrow> t  \<Longrightarrow>  (IF b THEN c\<^isub>1 ELSE c\<^isub>2, s) \<Rightarrow> t"
       
  1574 
       
  1575 | WhileFalse: "\<not>bval b s \<Longrightarrow> (WHILE b DO c,s) \<Rightarrow> s"
       
  1576 | WhileTrue:  "bval b s\<^isub>1  \<Longrightarrow>  (c,s\<^isub>1) \<Rightarrow> s\<^isub>2  \<Longrightarrow>  (WHILE b DO c, s\<^isub>2) \<Rightarrow> s\<^isub>3
       
  1577                \<Longrightarrow> (WHILE b DO c, s\<^isub>1) \<Rightarrow> s\<^isub>3"
       
  1578 
       
  1579 code_pred big_step .
       
  1580 
       
  1581 thm big_step.equation
  1524 
  1582 
  1525 section {* Examples for detecting switches *}
  1583 section {* Examples for detecting switches *}
  1526 
  1584 
  1527 inductive detect_switches1 where
  1585 inductive detect_switches1 where
  1528   "detect_switches1 [] []"
  1586   "detect_switches1 [] []"