src/HOL/Nominal/Examples/Height.thy
changeset 26262 f5cb9602145f
parent 25751 a4e69ce247e0
child 26648 25c07f3878b0
equal deleted inserted replaced
26261:b6a103ace4db 26262:f5cb9602145f
     3 theory Height
     3 theory Height
     4   imports "../Nominal"
     4   imports "../Nominal"
     5 begin
     5 begin
     6 
     6 
     7 text {*  
     7 text {*  
     8   A trivial problem suggested by D. Wang. It shows how
     8   A small problem suggested by D. Wang. It shows how
     9   the height of a lambda-terms behaves under substitution.
     9   the height of a lambda-terms behaves under substitution.
    10 *}
    10 *}
    11 
    11 
    12 atom_decl name
    12 atom_decl name
    13 
    13 
    15     Var "name"
    15     Var "name"
    16   | App "lam" "lam"
    16   | App "lam" "lam"
    17   | Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [100,100] 100)
    17   | Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [100,100] 100)
    18 
    18 
    19 text {* Definition of the height-function on lambda-terms. *} 
    19 text {* Definition of the height-function on lambda-terms. *} 
    20 
       
    21 consts 
    20 consts 
    22   height :: "lam \<Rightarrow> int"
    21   height :: "lam \<Rightarrow> int"
    23 
    22 
    24 nominal_primrec
    23 nominal_primrec
    25   "height (Var x) = 1"
    24   "height (Var x) = 1"
    44 apply(rule TrueI)+
    43 apply(rule TrueI)+
    45 apply(simp add: abs_fresh)
    44 apply(simp add: abs_fresh)
    46 apply(fresh_guess)+
    45 apply(fresh_guess)+
    47 done
    46 done
    48 
    47 
    49 text{* The next lemma is needed in the Var-case of the theorem. *}
    48 text{* The next lemma is needed in the Var-case of the theorem below. *}
    50 
    49 
    51 lemma height_ge_one: 
    50 lemma height_ge_one: 
    52   shows "1 \<le> (height e)"
    51   shows "1 \<le> (height e)"
    53 by (nominal_induct e rule: lam.induct) (simp_all)
    52 by (nominal_induct e rule: lam.induct) (simp_all)
    54 
    53 
    55 text {* 
    54 text {* 
    56   Unlike the proplem suggested by Wang, however, the 
    55   Unlike the proplem suggested by Wang, however, the 
    57   theorem is here formulated  entirely by using functions. 
    56   theorem is here formulated entirely by using functions. 
    58 *}
    57 *}
    59 
    58 
    60 theorem height_subst:
    59 theorem height_subst:
    61   shows "height (e[x::=e']) \<le> (((height e) - 1) + (height e'))"
    60   shows "height (e[x::=e']) \<le> ((height e) - 1) + (height e')"
    62 proof (nominal_induct e avoiding: x e' rule: lam.induct)
    61 proof (nominal_induct e avoiding: x e' rule: lam.induct)
    63   case (Var y)
    62   case (Var y)
    64   have "1 \<le> height e'" by (rule height_ge_one)
    63   have "1 \<le> height e'" by (rule height_ge_one)
    65   then show "height (Var y[x::=e']) \<le> height (Var y) - 1 + height e'" by simp
    64   then show "height (Var y[x::=e']) \<le> height (Var y) - 1 + height e'" by simp
    66 next
    65 next
    67   case (Lam y e1)
    66   case (Lam y e1)
    68   hence ih: "height (e1[x::=e']) \<le> (((height e1) - 1) + (height e'))" by simp
    67   hence ih: "height (e1[x::=e']) \<le> ((height e1) - 1) + (height e')" by simp
    69   moreover
    68   moreover
    70   have vc: "y\<sharp>x" "y\<sharp>e'" by fact+ (* usual variable convention *)
    69   have vc: "y\<sharp>x" "y\<sharp>e'" by fact+ (* usual variable convention *)
    71   ultimately show "height ((Lam [y].e1)[x::=e']) \<le> height (Lam [y].e1) - 1 + height e'" by simp
    70   ultimately show "height ((Lam [y].e1)[x::=e']) \<le> height (Lam [y].e1) - 1 + height e'" by simp
    72 next    
    71 next    
    73   case (App e1 e2)
    72   case (App e1 e2)
    74   hence ih1: "height (e1[x::=e']) \<le> (((height e1) - 1) + (height e'))" 
    73   hence ih1: "height (e1[x::=e']) \<le> ((height e1) - 1) + (height e')" 
    75     and ih2: "height (e2[x::=e']) \<le> (((height e2) - 1) + (height e'))" by simp_all
    74     and ih2: "height (e2[x::=e']) \<le> ((height e2) - 1) + (height e')" by simp_all
    76   then show "height ((App e1 e2)[x::=e']) \<le> height (App e1 e2) - 1 + height e'"  by simp 
    75   then show "height ((App e1 e2)[x::=e']) \<le> height (App e1 e2) - 1 + height e'"  by simp 
    77 qed
    76 qed
    78 
    77 
       
    78 theorem height_subst:
       
    79   shows "height (e[x::=e']) \<le> ((height e) - 1) + (height e')"
       
    80 proof (nominal_induct e avoiding: x e' rule: lam.induct)
       
    81   case (Var y)
       
    82   have "1 \<le> height e'" by (rule height_ge_one)
       
    83   then show "height (Var y[x::=e']) \<le> height (Var y) - 1 + height e'" by simp
       
    84 next
       
    85   case (Lam y e1)
       
    86   hence ih: "height (e1[x::=e']) \<le> ((height e1) - 1) + (height e')" by simp
       
    87   moreover
       
    88   have vc: "y\<sharp>x" "y\<sharp>e'" by fact+ (* usual variable convention *)
       
    89   ultimately show "height ((Lam [y].e1)[x::=e']) \<le> height (Lam [y].e1) - 1 + height e'" by simp
       
    90 next    
       
    91   case (App e1 e2)
       
    92   hence ih1: "height (e1[x::=e']) \<le> ((height e1) - 1) + (height e')" 
       
    93     and ih2: "height (e2[x::=e']) \<le> ((height e2) - 1) + (height e')" by simp_all
       
    94   then show "height ((App e1 e2)[x::=e']) \<le> height (App e1 e2) - 1 + height e'"  by simp 
       
    95 qed
       
    96 
       
    97 
    79 end
    98 end