removed experimental equality checking of closures; acknowledge underapproximation of equality in function name
authorhaftmann
Tue Dec 07 09:36:12 2010 +0100 (2010-12-07)
changeset 410376d6f23b3a879
parent 41036 4acbacd6c5bc
child 41040 a4a5a465da8d
child 41043 3750bdac1327
child 41069 6fabc0414055
removed experimental equality checking of closures; acknowledge underapproximation of equality in function name
src/HOL/ex/Normalization_by_Evaluation.thy
src/Tools/nbe.ML
     1.1 --- a/src/HOL/ex/Normalization_by_Evaluation.thy	Mon Dec 06 14:17:35 2010 -0800
     1.2 +++ b/src/HOL/ex/Normalization_by_Evaluation.thy	Tue Dec 07 09:36:12 2010 +0100
     1.3 @@ -66,7 +66,7 @@
     1.4  lemma "map (%f. f True) [id, g, Not] = [True, g True, False]" by normalization
     1.5  
     1.6  lemma "map (%f. f True) ([id, g, Not] @ fs) = [True, g True, False] @ map (%f. f True) fs"
     1.7 -  by normalization
     1.8 +  by normalization rule
     1.9  lemma "rev [a, b, c] = [c, b, a]" by normalization
    1.10  value [nbe] "rev (a#b#cs) = rev cs @ [b, a]"
    1.11  value [nbe] "map (%F. F [a,b,c::'x]) (map map [f,g,h])"
     2.1 --- a/src/Tools/nbe.ML	Mon Dec 06 14:17:35 2010 -0800
     2.2 +++ b/src/Tools/nbe.ML	Tue Dec 07 09:36:12 2010 +0100
     2.3 @@ -18,7 +18,7 @@
     2.4    val apps: Univ -> Univ list -> Univ        (*explicit applications*)
     2.5    val abss: int -> (Univ list -> Univ) -> Univ
     2.6                                               (*abstractions as closures*)
     2.7 -  val eq_Univ: Univ * Univ -> bool
     2.8 +  val same: Univ * Univ -> bool
     2.9  
    2.10    val put_result: (unit -> Univ list -> Univ list) -> Proof.context -> Proof.context
    2.11    val trace: bool Unsynchronized.ref
    2.12 @@ -183,27 +183,10 @@
    2.13    | apps (Const (name, xs)) ys = Const (name, ys @ xs)
    2.14    | apps (BVar (n, xs)) ys = BVar (n, ys @ xs);
    2.15  
    2.16 -fun satisfy_abs (abs as ((n, f), xs)) some_k =
    2.17 -  let
    2.18 -    val ys = case some_k
    2.19 -     of NONE => replicate n (BVar (0, []))
    2.20 -      | SOME k => map_range (fn l => BVar (k + l, [])) n;
    2.21 -  in (apps (Abs abs) ys, ys) end;
    2.22 -
    2.23 -fun maxidx (Const (_, xs)) = fold maxidx xs
    2.24 -  | maxidx (DFree _) = I
    2.25 -  | maxidx (BVar (l, xs)) = fold maxidx xs #> Integer.max (l + 1)
    2.26 -  | maxidx (Abs abs) = maxidx (fst (satisfy_abs abs NONE));
    2.27 -
    2.28 -fun eq_Univ (Const (k, xs), Const (l, ys)) = k = l andalso eq_list eq_Univ (xs, ys)
    2.29 -  | eq_Univ (DFree (s, k), DFree (t, l)) = s = t andalso k = l
    2.30 -  | eq_Univ (BVar (k, xs), BVar (l, ys)) = k = l andalso eq_list eq_Univ (xs, ys)
    2.31 -  | eq_Univ (x as Abs abs, y) =
    2.32 -      let
    2.33 -        val (x, ys) = satisfy_abs abs ((SOME o maxidx x o maxidx y) 0)
    2.34 -      in eq_Univ (x, apps y ys) end
    2.35 -  | eq_Univ (x, y as Abs _) = eq_Univ (y, x)
    2.36 -  | eq_Univ _ = false;
    2.37 +fun same (Const (k, xs), Const (l, ys)) = k = l andalso eq_list same (xs, ys)
    2.38 +  | same (DFree (s, k), DFree (t, l)) = s = t andalso k = l
    2.39 +  | same (BVar (k, xs), BVar (l, ys)) = k = l andalso eq_list same (xs, ys)
    2.40 +  | same _ = false;
    2.41  
    2.42  
    2.43  (** assembling and compiling ML code from terms **)
    2.44 @@ -258,7 +241,7 @@
    2.45    val name_const =  prefix ^ "Const";
    2.46    val name_abss =   prefix ^ "abss";
    2.47    val name_apps =   prefix ^ "apps";
    2.48 -  val name_eq =     prefix ^ "eq_Univ";
    2.49 +  val name_same =     prefix ^ "same";
    2.50  in
    2.51  
    2.52  val univs_cookie = (Univs.get, put_result, name_put);
    2.53 @@ -284,7 +267,7 @@
    2.54  fun nbe_abss 0 f = f `$` ml_list []
    2.55    | nbe_abss n f = name_abss `$$` [string_of_int n, f];
    2.56  
    2.57 -fun nbe_eq (v1, v2) = "(" ^ name_eq ^ " (" ^ nbe_bound v1 ^ ", " ^ nbe_bound v2 ^ "))";
    2.58 +fun nbe_same (v1, v2) = "(" ^ name_same ^ " (" ^ nbe_bound v1 ^ ", " ^ nbe_bound v2 ^ "))";
    2.59  
    2.60  end;
    2.61  
    2.62 @@ -370,7 +353,7 @@
    2.63          val (samepairs, args') = subst_nonlin_vars args;
    2.64          val s_args = map assemble_arg args';
    2.65          val s_rhs = if null samepairs then assemble_rhs rhs
    2.66 -          else ml_if (ml_and (map nbe_eq samepairs))
    2.67 +          else ml_if (ml_and (map nbe_same samepairs))
    2.68              (assemble_rhs rhs) default_rhs;
    2.69          val eqns = if is_eval then
    2.70              [([ml_list (rev (dicts @ s_args))], s_rhs)]