]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_proof_checking/cicReductionNaif.ml
Initial revision
[helm.git] / helm / ocaml / cic_proof_checking / cicReductionNaif.ml
index 1ab5e92bc49a64fe89a4829326658b7cdcab98e5..f569e75cd451f196a83ef95e86db8a735e07e206 100644 (file)
@@ -46,6 +46,7 @@ exception ReferenceToAxiom;;
 exception ReferenceToVariable;;
 exception ReferenceToCurrentProof;;
 exception ReferenceToInductiveDefinition;;
+exception RelToHiddenHypothesis;;
 
 (* takes a well-typed term *)
 let whd context =
@@ -55,8 +56,9 @@ let whd context =
    function
       C.Rel n as t ->
        (match List.nth context (n-1) with
-           C.Decl _ -> if l = [] then t else C.Appl (t::l)
-         | C.Def bo -> whdaux l (S.lift n bo)
+           Some (_, C.Decl _) -> if l = [] then t else C.Appl (t::l)
+         | Some (_, C.Def bo) -> whdaux l (S.lift n bo)
+        | None -> raise RelToHiddenHypothesis
        )
     | C.Var uri as t ->
        (match CicEnvironment.get_cooked_obj uri 0 with
@@ -89,7 +91,6 @@ let whd context =
          | C.CurrentProof (_,_,body,_) -> whdaux l body
          | C.InductiveDefinition _ -> raise ReferenceToInductiveDefinition
        )
-    | C.Abst _ as t -> t (*CSC l should be empty ????? *)
     | C.MutInd (uri,_,_) as t -> if l = [] then t else C.Appl (t::l)
     | C.MutConstruct (uri,_,_,_) as t -> if l = [] then t else C.Appl (t::l)
     | C.MutCase (mutind,cookingsno,i,_,term,pl) as t->
@@ -144,7 +145,7 @@ let whd context =
                  eat_first (num_to_eat,tl)
               in
                whdaux (ts@l) (List.nth pl (j-1))
-         | C.Abst _| C.Cast _ | C.Implicit ->
+         | C.Cast _ | C.Implicit ->
             raise (Impossible 2) (* we don't trust our whd ;-) *)
          | _ -> if l = [] then t else C.Appl (t::l)
        )
@@ -204,14 +205,23 @@ let are_convertible =
        match (t1,t2) with
           (C.Rel n1, C.Rel n2) -> n1 = n2
         | (C.Var uri1, C.Var uri2) -> U.eq uri1 uri2
-        | (C.Meta n1, C.Meta n2) -> n1 = n2
+        | (C.Meta (n1,l1), C.Meta (n2,l2)) -> 
+            n1 = n2 &&
+             List.fold_left2
+              (fun b t1 t2 ->
+                b &&
+                 match t1,t2 with
+                    None,_
+                  | _,None  -> true
+                  | Some t1',Some t2' -> aux context t1' t2'
+              ) true l1 l2
         | (C.Sort s1, C.Sort s2) -> true (*CSC da finire con gli universi *)
-        | (C.Prod (_,s1,t1), C.Prod(_,s2,t2)) ->
-           aux context s1 s2 && aux ((C.Decl s1)::context) t1 t2
-        | (C.Lambda (_,s1,t1), C.Lambda(_,s2,t2)) ->
-           aux context s1 s2 && aux ((C.Decl s1)::context) t1 t2
-        | (C.LetIn (_,s1,t1), C.LetIn(_,s2,t2)) ->
-           aux context s1 s2 && aux ((C.Def s1)::context) t1 t2
+        | (C.Prod (name1,s1,t1), C.Prod(_,s2,t2)) ->
+           aux context s1 s2 && aux ((Some (name1, (C.Decl s1)))::context) t1 t2
+        | (C.Lambda (name1,s1,t1), C.Lambda(_,s2,t2)) ->
+           aux context s1 s2 && aux ((Some (name1, (C.Decl s1)))::context) t1 t2
+        | (C.LetIn (name1,s1,t1), C.LetIn(_,s2,t2)) ->
+           aux context s1 s2 && aux ((Some (name1, (C.Def s1)))::context) t1 t2
         | (C.Appl l1, C.Appl l2) ->
            (try
              List.fold_right2 (fun  x y b -> aux context x y && b) l1 l2 true 
@@ -247,8 +257,9 @@ let are_convertible =
              aux context term1 term2 &&
              List.fold_right2 (fun x y b -> b && aux context x y) pl1 pl2 true
         | (C.Fix (i1,fl1), C.Fix (i2,fl2)) ->
-(*CSC: C.Decl e' giusto? *)
-           let tys = List.map (function (_,_,ty,_) -> C.Decl ty) fl1 in
+           let tys =
+            List.map (function (n,_,ty,_) -> Some (C.Name n,(C.Decl ty))) fl1
+           in
             i1 = i2 &&
              List.fold_right2
               (fun (_,recindex1,ty1,bo1) (_,recindex2,ty2,bo2) b ->
@@ -256,14 +267,15 @@ let are_convertible =
                  aux (tys@context) bo1 bo2)
               fl1 fl2 true
         | (C.CoFix (i1,fl1), C.CoFix (i2,fl2)) ->
-(*CSC: C.Decl e' giusto? *)
-           let tys = List.map (function (_,ty,_) -> C.Decl ty) fl1 in
+           let tys =
+            List.map (function (n,ty,_) -> Some (C.Name n,(C.Decl ty))) fl1
+           in
             i1 = i2 &&
              List.fold_right2
               (fun (_,ty1,bo1) (_,ty2,bo2) b ->
                 b && aux context ty1 ty2 && aux (tys@context) bo1 bo2)
               fl1 fl2 true
-        | (C.Abst _, _) | (_, C.Abst _) | (C.Cast _, _) | (_, C.Cast _)
+        | (C.Cast _, _) | (_, C.Cast _)
         | (C.Implicit, _) | (_, C.Implicit) ->
            raise (Impossible 3) (* we don't trust our whd ;-) *)
         | (_,_) -> false