]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/nCicReduction.ml
Final implementation of proof irrelevant conversion, which hadn't
[helm.git] / helm / software / components / ng_kernel / nCicReduction.ml
index 61bb201b7f685e0e6c3bf615c4b4406aba719cb5..4de73408fb2ff026a0481a18d24fa64af00c101b 100644 (file)
@@ -172,9 +172,9 @@ let whd = R.whd
 let (===) x y = Pervasives.compare x y = 0 ;;
 
 (* t1, t2 must be well-typed *)
-let are_convertible ?(subst=[]) get_relevance =
+let are_convertible ?(subst=[]) get_exact_relev =
  let rec aux test_eq_only context t1 t2 =
-   let rec alpha_eq test_eq_only t1 t2 =
+   let alpha_eq test_eq_only t1 t2 =
      if t1 === t2 then
        true
      else
@@ -222,11 +222,42 @@ let are_convertible ?(subst=[]) get_relevance =
              let term = NCicSubstitution.subst_meta l2 term in
               aux test_eq_only context t1 term
            with NCicUtils.Subst_not_found _ -> false)
+       
+       | (C.Appl ((C.Const r1) as hd1::tl1), C.Appl (C.Const r2::tl2)) 
+           when (Ref.eq r1 r2 && 
+             List.length (E.get_relevance r1) >= List.length tl1) ->
+         let relevance = E.get_relevance r1 in
+         let relevance = match r1 with
+             | Ref.Ref (_,Ref.Con (_,_,lno)) ->
+                 let _,relevance = HExtlib.split_nth lno relevance in
+                   HExtlib.mk_list false lno @ relevance
+             | _ -> relevance
+         in
+         (try
+             HExtlib.list_forall_default3_var
+              (fun t1 t2 b -> not b || aux test_eq_only context t1 t2 )
+              tl1 tl2 true relevance
+            with Invalid_argument _ -> false
+              | HExtlib.FailureAt fail ->
+                let relevance = get_exact_relev ~subst context hd1 tl1 in
+                let _,relevance = HExtlib.split_nth fail relevance in
+                let b,relevance = (match relevance with
+                  | [] -> assert false
+                  | b::tl -> b,tl) in
+                if (not b) then
+                  let _,tl1 = HExtlib.split_nth (fail+1) tl1 in
+                  let _,tl2 = HExtlib.split_nth (fail+1) tl2 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
+                else false)
 
-       | (C.Appl (hd1::tl1), C.Appl (hd2::tl2)) ->
+       | (C.Appl (hd1::tl1),  C.Appl (hd2::tl2)) ->
            aux test_eq_only context hd1 hd2 &&
-          let relevance = get_relevance ~subst context hd1 tl1 in
-           (try
+          let relevance = get_exact_relev ~subst context hd1 tl1 in
+            (try
              HExtlib.list_forall_default3
               (fun t1 t2 b -> not b || aux test_eq_only context t1 t2)
               tl1 tl2 true relevance
@@ -318,4 +349,13 @@ let rec head_beta_reduce ?(delta=max_int) ?(upto=(-1)) t l =
 
 let head_beta_reduce ?delta ?upto t = head_beta_reduce ?delta ?upto t [];;
 
+type stack_item = RS.stack_term
+type environment_item = RS.env_term
+
+type machine = int * environment_item list * NCic.term * stack_item list
+
+let reduce_machine = R.reduce
+let from_stack = RS.from_stack
+let unwind = R.unwind
+
 (* vim:set foldmethod=marker: *)