src/HOL/Induct/ABexp.thy
author wenzelm
Sat Feb 03 17:40:16 2001 +0100 (2001-02-03)
changeset 11046 b5f5942781a0
parent 5802 614f2f30781a
child 11649 dfb59b9954a6
permissions -rw-r--r--
Induct: converted some theories to new-style format;
     1 (*  Title:      HOL/Induct/ABexp.thy
     2     ID:         $Id$
     3     Author:     Stefan Berghofer, TU Muenchen
     4     Copyright   1998  TU Muenchen
     5 *)
     6 
     7 header {* Arithmetic and boolean expressions *}
     8 
     9 theory ABexp = Main:
    10 
    11 datatype 'a aexp =
    12     IF "'a bexp"  "'a aexp"  "'a aexp"
    13   | Sum "'a aexp"  "'a aexp"
    14   | Diff "'a aexp"  "'a aexp"
    15   | Var 'a
    16   | Num nat
    17 and 'a bexp =
    18     Less "'a aexp"  "'a aexp"
    19   | And "'a bexp"  "'a bexp"
    20   | Neg "'a bexp"
    21 
    22 
    23 text {* \medskip Evaluation of arithmetic and boolean expressions *}
    24 
    25 consts
    26   evala :: "('a => nat) => 'a aexp => nat"
    27   evalb :: "('a => nat) => 'a bexp => bool"
    28 
    29 primrec
    30   "evala env (IF b a1 a2) = (if evalb env b then evala env a1 else evala env a2)"
    31   "evala env (Sum a1 a2) = evala env a1 + evala env a2"
    32   "evala env (Diff a1 a2) = evala env a1 - evala env a2"
    33   "evala env (Var v) = env v"
    34   "evala env (Num n) = n"
    35 
    36   "evalb env (Less a1 a2) = (evala env a1 < evala env a2)"
    37   "evalb env (And b1 b2) = (evalb env b1 \<and> evalb env b2)"
    38   "evalb env (Neg b) = (\<not> evalb env b)"
    39 
    40 
    41 text {* \medskip Substitution on arithmetic and boolean expressions *}
    42 
    43 consts
    44   substa :: "('a => 'b aexp) => 'a aexp => 'b aexp"
    45   substb :: "('a => 'b aexp) => 'a bexp => 'b bexp"
    46 
    47 primrec
    48   "substa f (IF b a1 a2) = IF (substb f b) (substa f a1) (substa f a2)"
    49   "substa f (Sum a1 a2) = Sum (substa f a1) (substa f a2)"
    50   "substa f (Diff a1 a2) = Diff (substa f a1) (substa f a2)"
    51   "substa f (Var v) = f v"
    52   "substa f (Num n) = Num n"
    53 
    54   "substb f (Less a1 a2) = Less (substa f a1) (substa f a2)"
    55   "substb f (And b1 b2) = And (substb f b1) (substb f b2)"
    56   "substb f (Neg b) = Neg (substb f b)"
    57 
    58 lemma subst1_aexp_bexp:
    59   "evala env (substa (Var (v := a')) a) = evala (env (v := evala env a')) a \<and>
    60   evalb env (substb (Var (v := a')) b) = evalb (env (v := evala env a')) b"
    61     --  {* one variable *}
    62   apply (induct a and b)
    63          apply simp_all
    64   done
    65 
    66 lemma subst_all_aexp_bexp:
    67   "evala env (substa s a) = evala (\<lambda>x. evala env (s x)) a \<and>
    68   evalb env (substb s b) = evalb (\<lambda>x. evala env (s x)) b"
    69     -- {* all variables *}
    70   apply (induct a and b)
    71          apply auto
    72   done
    73 
    74 end