]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/nCicReduction.ml
meta VS meta in alpha_eq honors substitution
[helm.git] / helm / software / components / ng_kernel / nCicReduction.ml
index 5a8ba41648d861928bf223bf22a43b105f3f3be0..47c8ea74d3fa51068f9d32acfc85764b83f6d3a7 100644 (file)
@@ -351,7 +351,7 @@ module Reduction(RS : Strategy) =
       if k = 0 then t 
       else 
         NCicSubstitution.psubst ~avoid_beta_redexes:true  
-          true 0 (RS.from_env_for_unwind ~unwind) e t
+          (RS.from_env_for_unwind ~unwind) e t
     in
     if s = [] then t 
     else NCic.Appl(t::(RS.from_stack_list_for_unwind ~unwind s))
@@ -495,7 +495,7 @@ let are_convertible whd ?(subst=[])  =
        true
      else
        match (t1,t2) with
-       | (C.Sort (C.Type a), C.Sort (C.Type b)) -> a <= b
+       | (C.Sort (C.Type a), C.Sort (C.Type b)) when not test_eq_only -> a <= b
        | (C.Sort s1,C.Sort (C.Type _)) -> (not test_eq_only)
        | (C.Sort s1, C.Sort s2) -> s1 = s2
 
@@ -512,7 +512,7 @@ let are_convertible whd ?(subst=[])  =
 
        | (C.Meta (n1,(s1, C.Irl i1)), C.Meta (n2,(s2, C.Irl i2))) 
           when n1 = n2 && s1 = s2 -> true
-       | (C.Meta (n1,(s1, l1)), C.Meta (n2,(s2, l2))) when n1 = n2 -> 
+       | (C.Meta (n1,(s1, l1)), C.Meta (n2,(s2, l2))) when n1 = n2 &&
           let l1 = NCicUtils.expand_local_context l1 in
           let l2 = NCicUtils.expand_local_context l2 in
           (try List.for_all2 
@@ -520,7 +520,7 @@ let are_convertible whd ?(subst=[])  =
               (NCicSubstitution.lift s1 t1) 
               (NCicSubstitution.lift s2 t2))  
             l1 l2
-          with Invalid_argument _ -> assert false)
+          with Invalid_argument _ -> assert false) -> true
 
        | C.Meta (n1,l1), _ ->
           (try 
@@ -535,6 +535,15 @@ let are_convertible whd ?(subst=[])  =
               aux test_eq_only context t1 term
            with NCicUtils.Subst_not_found _ -> false)
 
+       | (C.Appl (C.Const r1::tl1), C.Appl (C.Const r2::tl2)) ->
+          r1 = r2 &&
+           let relevance = NCicEnvironment.get_relevance r1 in
+           (try
+             HExtlib.list_forall_default3
+              (fun t1 t2 b -> not b || aux test_eq_only context t1 t2)
+              tl1 tl2 true relevance
+            with Invalid_argument _ -> false)
+
        | (C.Appl l1, C.Appl l2) ->
           (try List.for_all2 (aux test_eq_only context) l1 l2
            with Invalid_argument _ -> false)
@@ -554,40 +563,39 @@ let are_convertible whd ?(subst=[])  =
      true
    else
      let height_of = function
-      | NCic.Const (NReference.Ref (_,NReference.Def h)) -> h
-      | NCic.Const (NReference.Ref (_,NReference.Fix (_,_,h))) -> h
-      | NCic.Appl(NCic.Const(NReference.Ref(_,NReference.Def h))::_) -> h
+      | NCic.Const (NReference.Ref (_,NReference.Def h)) 
+      | NCic.Const (NReference.Ref (_,NReference.Fix (_,_,h))) 
+      | NCic.Appl(NCic.Const(NReference.Ref(_,NReference.Def h))::_) 
       | NCic.Appl(NCic.Const(NReference.Ref(_,NReference.Fix (_,_,h)))::_) -> h
       | _ -> 0
      in
-     let small_delta_step (k1,env1,t1,s1 as m1) (k2,env2,t2,s2 as m2) = 
-       let h1 = height_of t1 and h2 = height_of t2 in
-       if h1 > h2 then
-         R.reduce ~delta:h2 ~subst context (k1,env1,t1,s1), m2, h2
-       else if h1 < h2 then
-         m1, R.reduce ~delta:h1 ~subst context (k2,env2,t2,s2), h1
-       else
-         let delta = max 0 (h1-1) in
-         R.reduce ~delta ~subst context (k1,env1,t1,s1),
-         R.reduce ~delta ~subst context (k2,env2,t2,s2),
-         delta
+     let small_delta_step (_,_,t1,_ as m1) (_,_,t2,_ as m2) = 
+       let h1 = height_of t1 in 
+       let h2 = height_of t2 in
+       let delta = if h1 = h2 then max 0 (h1 -1) else min h1 h2 in
+       R.reduce ~delta ~subst context m1,
+       R.reduce ~delta ~subst context m2,
+       delta
      in
      let rec convert_machines ((k1,e1,t1,s1 as m1),(k2,e2,t2,s2 as m2),delta) =
        (alpha_eq test_eq_only
          (R.unwind (k1,e1,t1,[])) (R.unwind (k2,e2,t2,[])) &&
+        let relevance =
+          match t1 with
+              C.Const r -> NCicEnvironment.get_relevance r
+            | _ -> [] in
         try
-         List.for_all 
-           (fun (t1,t2) ->
-             let t1 = RS.from_stack t1 and t2 = RS.from_stack t2 in
-             convert_machines (small_delta_step t1 t2))
-           (List.combine s1 s2)
+         HExtlib.list_forall_default3
+           (fun t1 t2 b  ->
+             not b ||
+             let t1 = RS.from_stack t1 in
+             let t2 = RS.from_stack t2 in
+             convert_machines (small_delta_step t1 t2)) s1 s2 true relevance
         with Invalid_argument _ -> false) || 
-       (let red delta = R.reduce ~delta ~subst context in
-        if delta = 0 then
-          alpha_eq test_eq_only (R.unwind (red 0 m1)) (R.unwind (red 0 m2))
-        else
+       (delta > 0 &&
           let delta = delta - 1 in 
-          convert_machines (red delta m1,red delta m2,delta))
+          let red = R.reduce ~delta ~subst context in
+          convert_machines (red m1,red m2,delta))
      in
      convert_machines (small_delta_step (0,[],t1,[]) (0,[],t2,[]))
  in