X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fmatita%2Fcontribs%2Fformal_topology%2Fbin%2Ftheory_explorer.ml;h=82850e40d2581be9943818389e972d5aa561cf03;hb=7329247b6325d8890f13898c25e68255e843e498;hp=5d3098d019c05889e462aba658f150a021bb74d4;hpb=4fd0802f846c1c011c9d393747b11d2bbc582269;p=helm.git diff --git a/helm/software/matita/contribs/formal_topology/bin/theory_explorer.ml b/helm/software/matita/contribs/formal_topology/bin/theory_explorer.ml index 5d3098d01..82850e40d 100644 --- a/helm/software/matita/contribs/formal_topology/bin/theory_explorer.ml +++ b/helm/software/matita/contribs/formal_topology/bin/theory_explorer.ml @@ -36,6 +36,9 @@ type equivalence_class = compound_operator * compound_operator list * equivalence_class list ref * equivalence_class list ref +let (===) (repr,_,_,_) (repr',_,_,_) = repr = repr';; +let (<=>) (repr,_,_,_) (repr',_,_,_) = repr <> repr';; + let string_of_equivalence_class (repr,others,leq,_) = String.concat " = " (List.map string_of_cop (repr::others)) ^ (if !leq <> [] then @@ -113,8 +116,9 @@ let ps_of_set (to_be_considered,under_consideration,news) ?processing (s,inf,sup output_string ch "}\n"; close_out ch; (*ignore (Unix.system "tred xxx.dot > yyy.dot && dot -Tps yyy.dot > xxx.ps")*) - ignore (Unix.system "dot -Tps xxx.dot > xxx.ps"); - ignore (read_line ()) + ignore (Unix.system "cp xxx.ps xxx_old.ps && dot -Tps xxx.dot > xxx.ps"); + (*ignore (read_line ())*) +;; let test to_be_considered_and_now ((s,_,_) as set) rel candidate repr = ps_of_set to_be_considered_and_now ~processing:(candidate,rel,repr) set; @@ -161,7 +165,7 @@ let test to_be_considered_and_now ((s,_,_) as set) rel candidate repr = print_endline (if res then "y" else "n"); res -let remove node = List.filter (fun node' -> node != node');; +let remove node = List.filter (fun node' -> node <=> node');; let add_leq_arc ((_,_,leq,_) as node) ((_,_,_,geq') as node') = leq := node' :: !leq; @@ -215,71 +219,79 @@ let geq_transitive_closure node node' = remove_transitive_arcs node node' ;; -let (@@) l1 e = if List.memq e l1 then l1 else l1@[e] +let (@@) l1 n = if List.exists (function n' -> n===n') l1 then l1 else l1@[n] + +let rec leq_reachable node = + function + [] -> false + | node'::_ when node === node' -> true + | (_,_,leq,_)::tl -> leq_reachable node (!leq@tl) +;; + +let rec geq_reachable node = + function + [] -> false + | node'::_ when node === node' -> true + | (_,_,_,geq)::tl -> geq_reachable node (!geq@tl) +;; let locate_using_leq to_be_considered_and_now ((repr,_,leq,_) as node) - ((_,_,sup) as set) + set start = - let rec aux is_sup ((nodes,inf,sup) as set) = + let rec aux ((nodes,inf,sup) as set) = function - [] -> - if is_sup then - nodes,inf,sup@@node - else - set + [] -> set | (repr',_,_,geq') as node' :: tl -> - if repr=repr' then aux is_sup set (!geq'@tl) - else if List.mem node' !leq - || test to_be_considered_and_now set SubsetEqual repr repr' - then + if repr=repr' then aux set (!geq'@tl) + else if leq_reachable node' !leq then + aux set tl + else if test to_be_considered_and_now set SubsetEqual repr repr' then begin + let sup = remove node sup in let inf = if !geq' = [] then (remove node' inf)@@node else inf in leq_transitive_closure node node'; - aux false (nodes,inf,sup) (!geq'@tl) + aux (nodes,inf,sup) (!geq'@tl) end else - aux is_sup set tl + aux set tl in -prerr_endline ("SUP: " ^ String.concat "," (List.map (fun (x,_,_,_) -> string_of_cop x) sup)); - aux true set sup + aux set start ;; exception SameEquivalenceClass of equivalence_class * equivalence_class;; let locate_using_geq to_be_considered_and_now ((repr,_,leq,geq) as node) - ((_,inf,_) as set) + set start = - let rec aux is_inf ((nodes,inf,sup) as set) = + let rec aux ((nodes,inf,sup) as set) = function - [] -> - if is_inf then - nodes,inf@@node,sup - else - set + [] -> set | (repr',_,leq',_) as node' :: tl -> - if repr=repr' then aux is_inf set (!leq'@tl) - else if List.mem node' !geq - || test to_be_considered_and_now set SupersetEqual repr repr' - then + if repr=repr' then aux set (!leq'@tl) + else if geq_reachable node' !geq then + aux set tl + else if test to_be_considered_and_now set SupersetEqual repr repr' then begin - if List.mem node' !leq then + if List.exists (function n -> n===node') !leq then (* We have found two equal nodes! *) raise (SameEquivalenceClass (node,node')) else begin + let inf = remove node inf in let sup = if !leq' = [] then (remove node' sup)@@node else sup in geq_transitive_closure node node'; - aux false (nodes,inf,sup) (!leq'@tl) + aux (nodes,inf,sup) (!leq'@tl) end end else - aux is_inf set tl + aux set tl in -prerr_endline ("INF: " ^ String.concat "," (List.map (fun (x,_,_,_) -> string_of_cop x) inf)); - aux true set inf + aux set start ;; let analyze_one to_be_considered repr hecandidate (news,((nodes,inf,sup) as set)) = +if not (List.for_all (fun ((_,_,_,geq) as node) -> !geq = [] && let rec check_sups = function [] -> true | (_,_,leq,_) as node::tl -> if !leq = [] then List.exists (fun n -> n===node) sup && check_sups tl else check_sups (!leq@tl) in check_sups [node]) inf) then (ps_of_set ([],None,[]) set; assert false); +if not (List.for_all (fun ((_,_,leq,_) as node) -> !leq = [] && let rec check_infs = function [] -> true | (_,_,_,geq) as node::tl -> if !geq = [] then List.exists (fun n -> n===node) inf && check_infs tl else check_infs (!geq@tl) in check_infs [node]) sup) then (ps_of_set ([],None,[]) set; assert false); let candidate = hecandidate::repr in if List.length (List.filter ((=) M) candidate) > 1 then news,set @@ -289,22 +301,62 @@ let analyze_one to_be_considered repr hecandidate (news,((nodes,inf,sup) as set) let geq = ref [] in let node = candidate,[],leq,geq in let nodes = nodes@[node] in - let set = nodes,inf,sup in - let set = locate_using_leq (to_be_considered,Some repr,news) node set in - let set = locate_using_geq (to_be_considered,Some repr,news) node set in + let set = nodes,inf@[node],sup@[node] in + let start_inf,start_sup = + let repr_node = + match List.filter (fun (repr',_,_,_) -> repr=repr') nodes with + [node] -> node + | _ -> assert false + in +inf,sup(* + match hecandidate with + I -> inf,[repr_node] + | C -> [repr_node],sup + | M -> inf,sup +*) + in + let set = + locate_using_leq (to_be_considered,Some repr,news) node set start_sup in +( +let _,inf,sup = set in +if not (List.for_all (fun ((_,_,_,geq) as node) -> !geq = [] && let rec check_sups = function [] -> true | (_,_,leq,_) as node::tl -> if !leq = [] then List.exists (fun n -> n===node) sup && check_sups tl else check_sups (!leq@tl) in check_sups [node]) inf) then (ps_of_set ([],None,[]) set; assert false); +if not (List.for_all (fun ((_,_,leq,_) as node) -> !leq = [] && let rec check_infs = function [] -> true | (_,_,_,geq) as node::tl -> if !geq = [] then List.exists (fun n -> n===node) inf && check_infs tl else check_infs (!geq@tl) in check_infs [node]) sup) then (ps_of_set ([],None,[]) set; assert false); +); + let set = + locate_using_geq (to_be_considered,Some repr,news) node set start_inf + in +( +let _,inf,sup = set in +if not (List.for_all (fun ((_,_,_,geq) as node) -> !geq = [] && let rec check_sups = function [] -> true | (_,_,leq,_) as node::tl -> if !leq = [] then List.exists (fun n -> n===node) sup && check_sups tl else check_sups (!leq@tl) in check_sups [node]) inf) then (ps_of_set ([],None,[]) set; assert false); +if not (List.for_all (fun ((_,_,leq,_) as node) -> !leq = [] && let rec check_infs = function [] -> true | (_,_,_,geq) as node::tl -> if !geq = [] then List.exists (fun n -> n===node) inf && check_infs tl else check_infs (!geq@tl) in check_infs [node]) sup) then (ps_of_set ([],None,[]) set; assert false); +); news@[candidate],set with - SameEquivalenceClass (node_to_be_deleted,node') -> + SameEquivalenceClass ((_,_,leq_d,geq_d) as node_to_be_deleted,node') -> let rec clean = function [] -> [] | (repr',others,leq,geq) as node::tl -> - leq := List.filter (function node -> node_to_be_deleted != node) !leq; - geq := List.filter (function node -> node_to_be_deleted != node) !geq; - if node==node' then + leq := + List.fold_right + (fun node l -> + if node_to_be_deleted <=> node then + node::l + else + !leq_d@l + ) !leq []; + geq := + List.fold_right + (fun node l -> + if node_to_be_deleted <=> node then + node::l + else + !geq_d@l + ) !geq []; + if node===node' then (repr',others@[candidate],leq,geq)::clean tl else - (repr',others,leq,geq)::clean tl + node::clean tl in let nodes = clean nodes in news,(nodes,inf,sup)